Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Passing null/undefined for options crashes node #1574

Closed
alanshaw opened this issue Sep 17, 2018 · 0 comments · Fixed by #1581
Closed

Passing null/undefined for options crashes node #1574

alanshaw opened this issue Sep 17, 2018 · 0 comments · Fixed by #1581
Labels
exp/novice Someone with a little familiarity can pick up kind/bug A bug in existing code (including security flaws) P1 High: Likely tackled by core team if no one steps up

Comments

@alanshaw
Copy link
Member

It's legal to pass null/undefined as a value for options. In some instances our API methods expect an options object to exist and try to access properties on it, which fails and crashes the node.

e.g.

if (options.hashAlg && options.cidVersion !== 1) {
options.cidVersion = 1
}

^^ in this instance, the default assignment only happens if options is undefined so does not work correctly if null is passed.

It could happen if the user is using a ternary to pass/not pass options e.g.

const hashAlg = 'sha2-512' // Obtained from user input perhaps
await ipfs.files.add(Buffer.from('data'), hashAlg ? { hashAlg } : null)`
@alanshaw alanshaw added kind/bug A bug in existing code (including security flaws) exp/novice Someone with a little familiarity can pick up status/ready Ready to be worked P1 High: Likely tackled by core team if no one steps up labels Sep 17, 2018
alanshaw added a commit that referenced this issue Sep 18, 2018
Options should be optional! Our API should be flexible enough to allow passing null or undefined in place of an options object. This PR fixes cases where we assume an options object has been passed.

fixes: #1574

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
alanshaw added a commit that referenced this issue Sep 18, 2018
Options should be optional! Our API should be flexible enough to allow passing null or undefined in place of an options object. This PR fixes cases where we assume an options object has been passed.

fixes: #1574

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
@ghost ghost removed the status/ready Ready to be worked label Sep 19, 2018
alanshaw added a commit that referenced this issue Sep 19, 2018
Options should be optional! Our API should be flexible enough to allow passing null or undefined in place of an options object. This PR fixes cases where we assume an options object has been passed.

fixes: #1574
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
exp/novice Someone with a little familiarity can pick up kind/bug A bug in existing code (including security flaws) P1 High: Likely tackled by core team if no one steps up
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant