libp2p / js-libp2p

The JavaScript Implementation of libp2p networking stack.
https://libp2p.io
Other
2.3k stars 440 forks source link

Undefined services causes exception #1757

Open marcus-pousette opened 1 year ago

marcus-pousette commented 1 year ago

Severity:

Low

Description:

Creating a libp2p instance with services that are undefined creates a null pointer exception even if it is allowed by the types

createLibp2p({
...,
    services: {
         abc: undefined
    }
})

To mitigate this I think there needs to be a null check before this https://github.com/libp2p/js-libp2p/blob/710da918a89b6f6ee5d03c0d14a311efd40a1b8f/src/libp2p.ts#L167 to check if createService is a function.

I ended up with this error because I am generating different configs based on conditions, and this leads me to assign "undefined" to services relay occasionally

achingbrain commented 1 year ago

Related: https://github.com/libp2p/js-libp2p/issues/1573

achingbrain commented 12 months ago

A runtime check seems reasonable but this really shouldn't be allowed by the types.

dhuseby commented 5 months ago

Will be closed by #2133 when that lands.

SgtPooki commented 1 week ago
JS Colo 2024 discussion still waiting on config validation PR..

no new updates