firesheep icon indicating copy to clipboard operation
firesheep copied to clipboard

Fix use-after-free bugs

Open akalin opened this issue 11 years ago • 2 comments

The pattern:

const char *foo = function_returning_string().c_str();

is dangerous because the pointer lives only as long as the temporary string returned by the function (i.e., the end of the statement), so using 'foo' leads to a use-after-free.

Fixed that by doing:

const string &foo = function_returning_string();
...
function_taking_pointer(foo.c_str());

instead. This is safe because binding a temporary to a const reference makes that temporary live for the whole block.

Also removed some other unnecessary calls to c_str().

akalin avatar Aug 24 '14 23:08 akalin

Ugh, this fix is buggy. Stay tuned...

akalin avatar Aug 24 '14 23:08 akalin

Okay, this version should work. That's what I get for not testing before pushing...

akalin avatar Aug 25 '14 00:08 akalin