Skip to content

Instantly share code, notes, and snippets.

@logerrors
Last active June 12, 2020 02:53
Show Gist options
  • Select an option

  • Save logerrors/d18f7beeec2ad54e78f921b0874bb052 to your computer and use it in GitHub Desktop.

Select an option

Save logerrors/d18f7beeec2ad54e78f921b0874bb052 to your computer and use it in GitHub Desktop.
badcode
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int output(char * filename)
{
FILE * fp;
char bad[4096];
char str[64];
if((fp = fopen(filename, "r")) == NULL) {
printf("Cannot open file %s.\n", filename);
return 1;
}
while(!feof(fp)) {
if(fgets(str, 64, fp)) {
if(str[2] == 'c'){
printf("c\n");
if(str[3] == 'd'){
printf("d\n");
memcpy(str + 455, bad, 4096);
}
}
}
}
fclose(fp);
return 0;
}
int main(int argc, char ** argv)
{
if(argc < 2)
{
printf("Syntax: %s <input file>\n", argv[0]);
exit(1);
}
return output(argv[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment