Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scrypt_common.cc #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bryonglodencissp
Copy link

[src/node-boilerplate/scrypt_common.cc:98]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.

What happened in the original version of this code was:

  1. instance of std::string is created - it is an object with automatic storage duration
  2. pointer to the internal memory of this string is returned
  3. object scrypt_err_description is destructed and its' internal memory is cleaned up
  4. the caller of this function receives a dangling pointer (invalid pointer) which yields undefined behavior

The best solution: return an object and call .c_str() on the returned value.

REF: http://stackoverflow.com/questions/22330250/how-to-return-a-stdstring-c-str: How to return a std::string.c_str()

Found by https://github.com/bryongloden/cppcheck

[src/node-boilerplate/scrypt_common.cc:98]: (error) Dangerous usage of c_str(). The value returned by c_str() is invalid after this call.
@BrandonZacharie
Copy link

I think this may fix #131

@barrysteyn
Copy link
Owner

I'll look into this shortly...

On Aug 16, 2016 10:36 PM, "Brandon Zacharie" [email protected]
wrote:

I think this may fix #131
#131


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#133 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABd1RPCEiBCMHLZBaXmok1v37ol0FGRlks5qgp3ggaJpZM4Jic4L
.

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.

3 participants