Re: how to avoid a memset() optimization

"Lars Duening" <lars@bearnip.com>
8 Nov 2002 10:59:25 -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)
Re: how to avoid a memset() optimization n2102139816.ch@chch.demon.co.uk (Charles Bryant) (2002-11-13)
[10 later articles]
| List of all articles for this month |
From: "Lars Duening" <lars@bearnip.com>
Newsgroups: comp.compilers
Date: 8 Nov 2002 10:59:25 -0500
Organization: Compilers Central
References: 02-11-030
Keywords: C, optimize, comment
Posted-Date: 08 Nov 2002 10:59:25 EST

Francis Wai <fwai@rsasecurity.com> wrote:


> 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. ...
>
> Various suggestions have been made, such as declaring the variable
> volatile and having a scrub memory function in a file of its own.


> [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]


Which is good news for the C/C++ crowd (at least those with compliant
compilers), but what about compilers for other languages?
[If they have something like volatile, use it. If not, you're on your
own. -John]


Post a followup to this message

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