uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

stack.c (414B)


      1 #include <err.h>
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include <string.h>
      5 
      6 int
      7 bof(char *str)
      8 {
      9 	char buf[24];
     10 
     11 	printf("addr: %p\n", buf);
     12 	strcpy(buf, str);
     13 	return (1);
     14 }
     15 
     16 int
     17 main(int argc, char *argv[])
     18 {
     19 	FILE *badfp;
     20 	char str[517];
     21 
     22 	if ((badfp = fopen("bad", "r")) == NULL)
     23 		err(1, "fopen(bad)");
     24 	fread(str, sizeof(char), 517, badfp);
     25 	fclose(badfp);
     26 	bof(str);
     27 	printf("returned\n");
     28 
     29 	return (0);
     30 }