Skip to content

fix: handle reallocation failure gracefully in DataPointer::resize()#37

Merged
jasnell merged 1 commit intonodejs:mainfrom
ndossche:clesss-3
Mar 23, 2026
Merged

fix: handle reallocation failure gracefully in DataPointer::resize()#37
jasnell merged 1 commit intonodejs:mainfrom
ndossche:clesss-3

Conversation

@ndossche
Copy link
Contributor

@ndossche ndossche commented Feb 18, 2026

Immediate reassignment leaves the buf.data pointer with a nullptr, leaking the original data. Furthermore, it leaves the length field inconsistent.
This patch first checks whether the pointer was a nullptr before reassigning.

Note: this was found by a static-dynamic analyser I'm developing.
I plan on sending a corresponding patch to Node itself after acceptance to handle call sites gracefully. Some places already do handle nulls correctly and don't cause a crash on a failed reallocation, but I'd have to double check.

Immediate reassignment leaves the `buf.data` pointer with a nullptr,
leaking the original data. Furthermore, it leaves the length field
inconsistent.
This patch first checks whether the pointer was a nullptr before
reassigning.
@jasnell jasnell merged commit 944c570 into nodejs:main Mar 23, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants