node-scrypt
node-scrypt copied to clipboard
Update scrypt_common.cc
[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:
- instance of
std::string
is created - it is an object with automatic storage duration - pointer to the internal memory of this string is returned
- object
scrypt_err_description
is destructed and its' internal memory is cleaned up - 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
I think this may fix https://github.com/barrysteyn/node-scrypt/issues/131
I'll look into this shortly...
On Aug 16, 2016 10:36 PM, "Brandon Zacharie" [email protected] wrote:
I think this may fix #131 https://github.com/barrysteyn/node-scrypt/issues/131
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/barrysteyn/node-scrypt/pull/133#issuecomment-240317895, or mute the thread https://github.com/notifications/unsubscribe-auth/ABd1RPCEiBCMHLZBaXmok1v37ol0FGRlks5qgp3ggaJpZM4Jic4L .