Skip to content

Buffer.allocUnsafe causes "Conditional jump..." on valgrind #26464

@kotsss

Description

@kotsss

Working with valgrind to clean a giant networking application I was getting "Conditional jump or move depends on uninitialised value(s)" with js stacks (see below), took a long time but managed to zero in on reason.

==28440== Conditional jump or move depends on uninitialised value(s)
==28440==    at 0xA7EBB08780A: ???
==28440==    by 0xA7EBB0118D4: ???
==28440==    by 0xA7EBB0118D4: ???
==28440==    by 0xA7EBB0118D4: ???
==28440==    by 0xA7EBB0118D4: ???
==28440==    by 0xA7EBB0118D4: ???
==28440==    by 0xA7EBB0118D4: ???
==28440==    by 0xA7EBB0118D4: ???
==28440==    by 0xA7EBB0118D4: ???
==28440==    by 0xA7EBB0118D4: ???
==28440==    by 0xA7EBB0118D4: ???
==28440==    by 0xA7EBB0118D4: ???

Running the following code through valgrind will trigger the error

const alloc = process.env.SAFE ? Buffer.alloc : Buffer.allocUnsafe;
var buf = alloc(20);
buf.writeInt32BE(123, 2);

>valgrind --gen-suppressions=yes --leak-check=full /var/lib/nave/global/10.13.0/bin/node a.js

I've managed to trace the cause to lib/internal/buffer.js:checkBounds accessing the buffer that isn't initialized.
Buffer.allocUnsafe used by ws npm module

Shachar

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions