Merge pull request #200 from xexyl/1994-schnitzi
Fix segfault in 1994/schnitzi - use fgets()
This commit is contained in:
2 files changed
+23
-9
No files matched your search
+21
-7
@@ -10,22 +10,36 @@
|
|||||||
|
|
||||||
make all
|
make all
|
||||||
|
|
||||||
### To run
|
## To run:
|
||||||
|
|
||||||
./schnitzi < textfile
|
./schnitzi < textfile
|
||||||
|
|
||||||
## Judges' comments
|
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed the entry to not
|
||||||
|
overflow the buffer (and segfault) by changing the call of `gets()` to
|
||||||
|
`fgets()`. He also increased the buffer size. Prior to this fix one could not
|
||||||
|
redirect the Makefile into this program, as an example problem. Thank you Cody
|
||||||
|
for your assistance!
|
||||||
|
|
||||||
Try:
|
|
||||||
|
## Try:
|
||||||
|
|
||||||
./schnitzi < /etc/motd
|
./schnitzi < /etc/motd
|
||||||
|
./schnitzi < /etc/passwd
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Judges' comments:
|
||||||
|
|
||||||
|
|
||||||
|
Try:
|
||||||
|
|
||||||
./schnitzi < schnitzi.c
|
./schnitzi < schnitzi.c
|
||||||
|
|
||||||
Compare the output of the program with its source. Sure the output
|
Compare the output of the program with its source. Sure the output
|
||||||
is different, but there is more than meets the diff's eye. Can you
|
is different, but there is more than meets the `diff`'s eye. Can you
|
||||||
find out why?
|
find out why?
|
||||||
|
|
||||||
## Author's comments
|
## Author's comments:
|
||||||
|
|
||||||
SPOILER:
|
SPOILER:
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ h mh111 de{l) +di (+'( d+% c n+
|
|||||||
*/ n = 0 ;
|
*/ n = 0 ;
|
||||||
main ( ) {
|
main ( ) {
|
||||||
char v [
|
char v [
|
||||||
100 ] , s;
|
1000 ] , s;
|
||||||
int t[100 ] ,
|
int t[100 ] ,
|
||||||
u[100 ] ; u
|
u[100 ] ; u
|
||||||
[ 0
|
[ 0
|
||||||
]=ftell(stdin ) ;
|
]=ftell(stdin ) ;
|
||||||
while(gets (v ) )
|
while(fgets(v,100,stdin )&&((v[strlen(v)-1]='\0',1)) )
|
||||||
{t [ r ]=
|
{t [ r ]=
|
||||||
strlen (
|
strlen (
|
||||||
v);y=
|
v);y=
|
||||||
|
|||||||
Reference in new issue
Block a user