Does writing program using global variables is safer?
Posted
by
ZoZo123
on Stack Overflow
See other posts from Stack Overflow
or by ZoZo123
Published on 2012-04-09T17:01:36Z
Indexed on
2012/04/09
17:30 UTC
Read the original article
Hit count: 194
I was reading about buffer, stack and heap overflows. I read this post as well. my question is like that: if I use only global variables in my code, can I say it prevents all the exploits of overflow?
let's say I have this buffers in code declared in the global scope:
char buf1[10];
char buf2[100];
If I send buf1
as the buffer to recv(int s, char *buf, int len,int flags);
- I will overwrite the data segment and may ruin the
buf2
content, right? - Would I be able to run a code from it because as I know it is not a code segment and data segment is not executable.
Can we conclude that using Globals is the safest way?
© Stack Overflow or respective owner