Skip to content

Commit

Permalink
Prevent buffer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ikozyris authored Dec 14, 2022
1 parent 2b63a77 commit f08d643
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int interactive()
memset(txt, '\0', sizeof(txt));//reset txt
lines = 1;
printf("Enter file name to read: ");
scanf("%s", fname);
scanf("%37s", fname);
fp = fopen(fname,"r");
if(fp == NULL)
{
Expand Down Expand Up @@ -65,7 +65,7 @@ int interactive()
}
txt[index] = '\0';
printf("Enter file name to write: ");
scanf("%s", fname); //naming the file and allowing up to 19 chars
scanf("%37s", fname); //naming the file and allowing up to 19 chars
fp = fopen(fname, "w");
fprintf(fp, "%s", txt); //creates file
fclose(fp); //closes file
Expand All @@ -82,7 +82,7 @@ int interactive()
}
txt[index] = '\0';
printf("Enter file name to write: ");
scanf("%s", fname); //naming the file and allowing up to 19 chars
scanf("%37s", fname); //naming the file and allowing up to 19 chars
fp = fopen(fname, "a");
fprintf(fp, "%s", txt); //creates file
fclose(fp); //closes file
Expand Down

0 comments on commit f08d643

Please sign in to comment.