curl / Mailing Lists / curl-library / Single Mail


Re: Security fix: reset memory of Curl_easy->UserDefined->str

From: Harold Tessmann III <>
Date: Sun, 4 Mar 2018 21:10:09 -0500

On 3/1/18, Prashant Chaudhari <> wrote:

> I would like to add attached patch, which zero out the user defined data. I
> am particularly targeting to reset the password/authentication secrets.

I gave the proposed fix a quick look and think that it does not
actually meet the stated goal of securely overwriting sensitive data.
The correct fix will take more work, and I don't like this change
as-is because it gives the reader a false sense of security.

The first problem is that any decent optimizing compiler will see the
memset() followed by free() as a dead store and will optimize it away.
is a pretty good description of how and why that works. The bad news
is that there is no portable function that does the job. memset_s() is
available on some (many? most?) UNICes, but it's fairly recent (C11);
on Windows you would use SecureZeroMemory(). For more on the topic,
read <> and

The second, harder, problem is that you have no guarantee that the
sensitive data is only stored in that location. On a system has swap
enabled without encryption, it is very possible for the sensitive data
to be swapped to disk, which copy will be unaffected by any secure
memory overwrite function you can find. To be more safe, we would need
to tell the OS to allocate some memory that it will never swap, which
task is also non-portable.

And even if we solve those two problems, I won't say for sure that we
have securely erased the sensitive data. Just because I can't think of
another route of attack doesn't mean that none exists.

Received on 2018-03-05