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

Passing null/undefined for options crashes node #1574

Closed
@alanshaw

Description

@alanshaw

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)`

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High: Likely tackled by core team if no one steps upexp/noviceSomeone with a little familiarity can pick upkind/bugA bug in existing code (including security flaws)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions