Switch from strdup to memcpy to faithfully copy all bytes and prevent a crash in some cases. #966
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a pull request to fix the issue I created over here: #965
To summarize over here why I'm making these changes:
strdupexpects a C-style null-terminated string, but sometimes we're using nodejs strings to pass in strings that contain nulls in the middle, thus failing to copy everything at best, and causing crashes from reading invalid memory locations at worst.malloc,memcpyandmemsetto prevent these issues.To explain my changes a little bit:
memsetinstead of the more standard array-style access because most of the usages of these templates areconst char *.void *instead ofconst char *, so to get the pointer arithmetic right, I had to specify thechar *.C code isn't what I normally write, so let me apologize in advance if these changes aren't quite what they should be 😄
I'm happy to make any modifications necessary.
The limited testing I've done seems to show that everything is working perfectly well with these changes.