[PATCH] memset 0 in obscure is optimized away by compiler

Harald Becker ralda at gmx.de
Wed Apr 16 17:51:42 UTC 2014


Hi Tito !

>my fear is/was that the call to memset is totally
>optimized away when optimization is turned on
>and therefore the memory containing the password
>strings is not zeroed at all.

This would be a completely ill behavior of compiler optimization.
Normally such things as memset are replaced by alternative code
to fill the memory by the given value. Such code may in some
circumstances even be shorter than calling a function, not only
faster.

I do only know one case where the memset may be optimized to
nothing, that is, when you fill content of an auto variable near
end of a function, and don't further access that memory space.
That would be same as something like:

int func( int i, j )
{
  int x;

  ... // put any code here using variable x

  x = 0;  // this may be optimized away, as x is not accessed
  after setting it to a value

  return i + j; 
}


>Sadly my understanding of assembler is near to zero
>so I only can see that memset is not there but not if it
>is substituted by something else by the compiler
>in the latter case the patch could still be applied
>to be cohoerent with other busybox code.

If you use x86 code you may send me the assembler listing, so I'm
able to help you with your clarification process.

--
Harald


More information about the busybox mailing list