www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - what is exactly stack stomp "-gx" new switch ?

reply "Klb" <Klb somewhere.ut> writes:
...and any example where this switch will be usefull ?
Jul 15 2014
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
Klb:

 ...and any example where this switch will be usefull ?
I guess it was added to D in the spirit of "If you have to ask what it is, then you don't need to use it". More seriously, I too would like more documentation about its use cases. Bye, bearophile
Jul 15 2014
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 07/15/2014 04:33 PM, bearophile wrote:
 Klb:

 ...and any example where this switch will be usefull ?
I guess it was added to D in the spirit of "If you have to ask what it is, then you don't need to use it". More seriously, I too would like more documentation about its use cases. Bye, bearophile
Just from the name of it, it sounds like the program stack will be cleared at certain times, likely when exiting functions, to clear sensitive information. And my test supports that idea. Here is some malicious function trying to read data from the stack's earlier contents: import std.stdio; void foo(char c) { char buffer[100]; foreach (ref b; buffer) { b = c; } } void malicious() { char buffer[100] = void; writeln("Let's see what we'll find on the stack..."); foreach (b; buffer) { write(b); } writeln; } void main() { foo('a'); malicious(); } When I run the program without -gx, malicious() prints the contents that are left from foo()'s execution. Ali
Jul 15 2014
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 07/15/2014 04:56 PM, Ali Çehreli wrote:

      char buffer[100];
[...]
      char buffer[100] = void;
Before others point out, those are in C syntax by mistake. :) They should preferably be: char[100] buffer; [...] char[100] buffer = void; Ali
Jul 15 2014