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

2022-10-05 Thread Rolf Eike Beer
Am Samstag, 1. Oktober 2022, 21:48:39 CEST schrieb Bernhard Reutner-Fischer: > On Wed, 16 Apr 2014 20:25:39 -0400 > > > That's exactly the situation here. The lifetime of the object being > > cleared by memset ends sufficiently close to the memset that the > > compiler is able to achieve the same

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

2022-10-01 Thread Bernhard Reutner-Fischer
On Sat, 1 Oct 2022 21:48:39 +0200 Bernhard Reutner-Fischer wrote: > On Wed, 16 Apr 2014 20:25:39 -0400 > > > That's exactly the situation here. The lifetime of the object being > > cleared by memset ends sufficiently close to the memset that the > > compiler is able to achieve the same

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

2022-10-01 Thread Bernhard Reutner-Fischer
On Wed, 16 Apr 2014 20:25:39 -0400 > That's exactly the situation here. The lifetime of the object being > cleared by memset ends sufficiently close to the memset that the > compiler is able to achieve the same observable effects that would be > seen in the abstract machine without actually

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

2014-04-16 Thread Tito
Hi, while reading some interesting stuff about memset being optimized away by compilers if the variable is not read after the memset call I recalled there was something similar in libbb/obscure.c file: static int string_checker(const char *p1, const char *p2) { int size, i; /*

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

2014-04-16 Thread Harald Becker
Hi Tito ! I've tried to find out if memset is really optimized away in this case with some test code that I've compiled with : What is wrong with optimization of code, e.g. replacing call to memset by a quick loop which does same thing even faster than a function call? ... beside that such

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

2014-04-16 Thread Tito
On Wednesday 16 April 2014 19:14:05 you wrote: Hi Tito ! I've tried to find out if memset is really optimized away in this case with some test code that I've compiled with : What is wrong with optimization of code, e.g. replacing call to memset by a quick loop which does same thing even

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

2014-04-16 Thread Rich Felker
On Wed, Apr 16, 2014 at 07:14:05PM +0200, Harald Becker wrote: Hi Tito ! I've tried to find out if memset is really optimized away in this case with some test code that I've compiled with : What is wrong with optimization of code, e.g. replacing call to memset by a quick loop which does

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

2014-04-16 Thread Harald Becker
Hi Rich ! The quick loop will equally be optimized away, as neither it nor the memset have any observable effect. What do you call observable? Replacing the content of a memory region by a constant value is an observable effect by itself. The only case I know is, filling an automatic variable at

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

2014-04-16 Thread Harald Becker
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

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

2014-04-16 Thread Denys Vlasenko
On Wed, Apr 16, 2014 at 6:47 PM, Tito farmat...@tiscali.it wrote: Hi, while reading some interesting stuff about memset being optimized away by compilers if the variable is not read after the memset call I recalled there was something similar in libbb/obscure.c file: static int

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

2014-04-16 Thread Harald Becker
Hi Rich ! I got a mail error, saying dal...@libc.org has no valid mail exchanger??? What's wrong? -- Harald ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox

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

2014-04-16 Thread Cathey, Jim
Generally C compilers assume that an address passed to a function (free(p)) _might_ be dereferenced, and so would not optimize away the memset(p,...) If a particular C compiler thinks it knows what free() is, and that it doesn't dereference its argument, then it might think it was justified in

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

2014-04-16 Thread Tito
On Wednesday 16 April 2014 20:01:38 Cathey, Jim wrote: Generally C compilers assume that an address passed to a function (free(p)) _might_ be dereferenced, and so would not optimize away the memset(p,...) If a particular C compiler thinks it knows what free() is, and that it doesn't

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

2014-04-16 Thread Cathey, Jim
char pwd[64]; memset(pwd, 0, sizeof(pwd)); if (pwd[0] != '\0') { printf(memory not zeroed); or would the compiler see that we read just first char and zero only that and force us to check every char of pwd? If CC knows what memset does (and I believe they generally do these days),

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

2014-04-16 Thread Harald Becker
Hi Tito ! void getPassword(void) { char pwd[64]; if (GetPassword(pwd, sizeof(pwd))) { /* checking of password, secure operations, etc */ } memset(pwd, 0, sizeof(pwd)); if (pwd[0] != '\0') { printf(memory not zeroed); exit(1) } } just out of curiosity and for me to

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

2014-04-16 Thread Cathey, Jim
What do you call observable? C has a pretty exact definition of this. Replacing the content of a memory region by a constant value is an observable effect by itself. No, it's not. Where did you _get_ the address to observe? That's the essence of the observability question. The C compiler

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

2014-04-16 Thread Harald Becker
Hi Jim ! Mind you, I don't think I like my compiler being quite that 'smart'. I would hope there was a knob someplace to tell it not to be quite so, umm, _free_ with free()! That knob is part of the function definition. on a standard function definition like: void free( void* ptr ); with

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

2014-04-16 Thread Rich Felker
On Wed, Apr 16, 2014 at 07:51:42PM +0200, Harald Becker wrote: 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