how to avoid a memset() optimization

"Francis Wai" <fwai@rsasecurity.com>
7 Nov 2002 00:51:51 -0500

          From comp.compilers

Related articles
how to avoid a memset() optimization fwai@rsasecurity.com (Francis Wai) (2002-11-07)
Re: how to avoid a memset() optimization lars@bearnip.com (Lars Duening) (2002-11-08)
Re: how to avoid a memset() optimization alexc@world.std.com (Alex Colvin) (2002-11-08)
Re: how to avoid a memset() optimization fjh@cs.mu.OZ.AU (Fergus Henderson) (2002-11-12)
Re: how to avoid a memset() optimization christian.bau@freeserve.co.uk (Christian Bau) (2002-11-12)
Re: how to avoid a memset() optimization lars@bearnip.com (Lars Duening) (2002-11-12)
Re: how to avoid a memset() optimization cgweav@aol.com (Clayton Weaver) (2002-11-12)
[11 later articles]
| List of all articles for this month |
From: "Francis Wai" <fwai@rsasecurity.com>
Newsgroups: comp.compilers
Date: 7 Nov 2002 00:51:51 -0500
Organization: http://groups.google.com/
Keywords: C
Posted-Date: 07 Nov 2002 00:51:51 EST

In a recent article (http://online.securityfocus.com/archive/82/297827),
Peter Gutmann raised a concern which has serious implications in
secure programming. His example, along the lines of,


int main()
{
        char key[16];
        strcpy(key, "whatever");
        encrpts(key);
        memset(key, 0, 16);
}


where memset() was optimized away because memset() is the last
expression before the next sequence point and that its side-effect is
not needed and that the subject of memset() is an auto variable. The
compiler sees that it is legitimate to optimize it away. This is _bad_
news for anyone concerns with sensitive data being left lying around
in memory.


Various suggestions have been made, such as declaring the variable
volatile and having a scrub memory function in a file of its own. I'm
wondering if there are better ways such as telling the compiler not to
optimize away a function call.
[Declaring the array volatile is the right way to do it. The reason
volatile exists is to tell the compiler not to do otherwise valid
optimizations. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.