Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Don't ask why I am not posting this at Stack. So I have this small C program. It returns the address of the environment variable specified in argv[1].

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
    printf("%s is at %p\n", argv[1], getenv(argv[1]));

What's irritating is that on Ubuntu Linux 2.6.20-15 x86 it returns the same address every time the program is run.

enter image description here

However on Ubuntu Linux 3.2.0-37 x86 it returns a different address each time. So what's new with the new kernel?

enter image description here

share|improve this question
You're leaving out crucial details. What do you mean "different address"? Examples? – Isaac Rabinovitch Feb 15 '13 at 23:07
This might be related to ASLR, which causes every new process to have different locations for their stack. – grawity Feb 15 '13 at 23:23
@grawity as per Wikipedia: Linux has enabled a weak form of ASLR by default since kernel version 2.6.12 (released June 2005). – WikiWitz Feb 15 '13 at 23:33
To potential close voters: This is a question about the kernel's behavior. The C code is just used illustrate the "symptoms". I think this is perfectly on topic here. – Dennis Feb 16 '13 at 13:30
It was able to find your desired env variable and return an address for it... it works exactly as described on the tin... expecting the same address is an odd concept. If you add or remove env vars, the address would change, ASLR has been around a while too. What would be strange would be you not getting an address. It's all the same, regardless where the data is stored. (and turtles all the way down!) – lornix Jun 16 '14 at 9:14

1 Answer 1

The Linux kernel has a feature that does memory address randomization for security. Its purpose is to prevent reliable buffer overflow attacks. Possibly you have that enabled on one box, but not on the other. check sysctl for howto enable and disable it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.