I came across this question when I was reading about vulnerable C programs involving strtol. Below is the code
#include <stdio.h>
void f (int i, int j) {
int a[50];
a[i] += j;
}
int main (int argc, char *argv[]) {
int x = 10, y, z;
if (argc > 1) {
y = strtol (argv[1], NULL, 10);
z = strtol (argv[2], NULL, 10);
f(y, z);
x = 20;
printf ("x=%d\n", x);
}
return 0;
}
The call strtol(s, NULL, 10)
returns the integer written as
string s in decimal notation. What inputs should one be giving to print x value as 10 and what is the idea behind giving those inputs?