I'm learning about security. Here is some sample code I've been given:
#include <stdio.h>
#include <string.h>
char *j; /* use to dump the stack in function cat */
/* Strings to be copied into buffer in function cat */
char str1[] = "";
char str2[] = "";
int main() {
void cat(int *parm) {
char buffer[8];
/* Dump the stack for function cat */
for (j=buffer; j<((char *)&parm); j++)
printf("%p: 0x%x\n", j, *(unsigned char *)j);
/* copy str1 followed by str2 into buffer */
/* note that a \0 remains between str1 and str2 in buffer */
strcpy(buffer, str1);
strcpy(&buffer[strlen(str1)+1], str2);
}
int *arg; /* dummy argument for call to function cat */
int x;
x = 0;
cat(arg);
x = 1;
printf("%d\n",x);
}
I'm compiling with GCC. All I'm getting is "1" though. Any ideas why?
Also, my goal is to eventually get the program to print out "0", and achieve this by only adding code to cat(). I can't change anything already there, just add. Any help to get me started in the right direction.