Switch from strdup to memcpy to faithfully copy all bytes and prevent a crash in some cases.#966
Merged
johnhaley81 merged 2 commits intonodegit:masterfrom Mar 24, 2016
Merged
Conversation
… a crash in some cases.
Contributor
Author
|
Okay, not sure what I did wrong to fail the Travis CI build, this is the only error I see: Did I do that? Or is there some other error I'm missing? Or is there just some intermittent CI failure? |
Collaborator
|
@tylerchurch it's an intermittent CI failure. I restarted the test. I was seeing the same on #958 |
Collaborator
|
Ok, that took me a moment to get my head around. Would you mind doing a summary of the comments above in the code? I know that later I'm going to look at that and go "WTF??" |
Collaborator
|
Thanks @tylerchurch! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.