Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does &variable as a expression mean in c

Tags:

c

reference

this is the snippet of a program code :

 char authenticated = 0;
 char guard1 = 234;
 char guard2 = 234;
 //more variables initliased...
 char buf[128];

 &authenticated;
 &guard1;
 &guard2;

So what does it mean when the reference stands there as a single expression in the program code?

Edit: More Context : It's compiled with gcc on a debian server and it's related to a security project, where you can overflow the buf array.

like image 863
amaik Avatar asked Nov 05 '14 20:11

amaik


People also ask

What the Fox say Meaning?

Speaking of the meaning of the song, Vegard characterizes it as coming from "a genuine wonder of what the fox says, because we didn't know". Although interpreted by some commentators as a reference to the furry fandom, the brothers have stated they did not know about its existence when producing "The Fox".

What Does the Fox Say year?

“The Fox (What Does the Fox Say?)” by Ylvis was released in September 2013, and it's become one of the most beloved gimmick songs of the past half-decade.

How can I find a song by the sound?

On your phone, touch and hold the Home button or say "Hey Google." Ask "What's this song?" Play a song or hum, whistle, or sing the melody of a song. Hum, whistle, or sing: Google Assistant will identify potential matches for the song.


1 Answers

Given that this is for a security project, my guess is that these statements are designed to prevent the compiler from optimizing away the authenticated, guard1, and guard2 variables. If these variables aren't used later on in the function, a compliant C compiler could optimize them away, changing the layout of the stack frame for the function call.

Technically speaking, since these statements have no side-effects, the compiler could in principle optimize them away as well. However, the sense I get is that the intended compiler doesn't do this (not that it couldn't do it, just that it can't do it). That way, the layout of the stack frame will have the authenticated variable shielded by two char values that are not null terminators, potentially making it a bit trickier to overwrite authenticated. Of course, it sounds like your assignment is specifically to change authenticated, so it's not foolproof. :-)

Hope this helps!

like image 93
templatetypedef Avatar answered Oct 04 '22 07:10

templatetypedef