Merge pull request #249 from xexyl/1994-schnitzi
This commit is contained in:
3 files changed
+70
-9
No files matched your search
@@ -14,11 +14,15 @@
|
|||||||
|
|
||||||
./schnitzi < textfile
|
./schnitzi < textfile
|
||||||
|
|
||||||
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed the entry to not
|
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) increased the buffer
|
||||||
overflow the buffer (and segfault) by changing the call of `gets()` to
|
size from 100 to 10000. Changing it to use `fgets()` instead of `gets()` is more
|
||||||
`fgets()`. He also increased the buffer size. Prior to this fix one could not
|
problematic because when feeding the source code to the program the output
|
||||||
redirect the Makefile into this program, as an example problem. Thank you Cody
|
results in compiler errors and not only that but the gets() is still there in
|
||||||
for your assistance!
|
the generated output. Even changing the buffer size can result in compilation
|
||||||
|
errors if not done correctly. The generated output also does not have a changed
|
||||||
|
buffer size. Changing it to use fgets() can happen later, maybe, but bigger
|
||||||
|
files can now be parsed by the original code. An example is this Makefile. Thank
|
||||||
|
you Cody!
|
||||||
|
|
||||||
|
|
||||||
## Try:
|
## Try:
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ h mh111 de{l) +di (+'( d+% c n+
|
|||||||
*/ n = 0 ;
|
*/ n = 0 ;
|
||||||
main ( ) {
|
main ( ) {
|
||||||
char v [
|
char v [
|
||||||
1000 ] , s;
|
10000 ] , s;
|
||||||
int t[100 ] ,
|
int t[100 ] ,
|
||||||
u[100 ] ; u
|
u[100 ] ; u
|
||||||
[ 0
|
[ 0
|
||||||
]=ftell(stdin ) ;
|
]=ftell(stdin ) ;
|
||||||
while(fgets(v,100,stdin )&&((v[strlen(v)-1]='\0',1)) )
|
while(gets (v ) )
|
||||||
{t [ r ]=
|
{t [ r ]=
|
||||||
strlen (
|
strlen (
|
||||||
v);y=
|
v);y=
|
||||||
|
|||||||
@@ -453,6 +453,63 @@ this simply does not work with them. Can you help us?
|
|||||||
|
|
||||||
# 1994
|
# 1994
|
||||||
|
|
||||||
|
## [1994/schnitzi](1994/schnitzi.c) ([README.md])(1994/schnitzi/README.md))
|
||||||
|
## STATUS: uses gets() - change to fgets() if possible
|
||||||
|
|
||||||
|
The original buffer size of this entry is 100 which is very easily overflowed
|
||||||
|
with `gets()` which it uses. [Cody Boone
|
||||||
|
Ferguson](/winners.html#Cody_Boone_Ferguson) changed the buffer size to 10000
|
||||||
|
but he notes a problem in that this does not translate to the generated source
|
||||||
|
file (when feeding the source itself). With `fgets()` it generates compiler
|
||||||
|
errors. Without special care with changing the buffer size it would also
|
||||||
|
generate compiler errors. Cody explains the magic below which might be used to
|
||||||
|
change this entry to fgets() (and he'll be working on it in the coming days most
|
||||||
|
likely).
|
||||||
|
|
||||||
|
### The magic of the entry
|
||||||
|
|
||||||
|
Take a look at the interesting comment as well as the `int r=0,x,y=0` at the top
|
||||||
|
of the file. If you look at each column go down that column you can see how it
|
||||||
|
spells out the code. For instance the first column looks like:
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
i
|
||||||
|
n
|
||||||
|
c
|
||||||
|
l
|
||||||
|
u
|
||||||
|
d
|
||||||
|
e
|
||||||
|
|
||||||
|
<
|
||||||
|
s
|
||||||
|
t
|
||||||
|
d
|
||||||
|
i
|
||||||
|
o
|
||||||
|
.
|
||||||
|
h
|
||||||
|
>
|
||||||
|
```
|
||||||
|
|
||||||
|
If you join the lines you end up with:
|
||||||
|
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include <stdio.h>
|
||||||
|
```
|
||||||
|
|
||||||
|
If you look at column 25 which is the end of the word 'mh111' and you go down to
|
||||||
|
the next row you'll see a 0 and if you go one row down another 0. This is the
|
||||||
|
buffer size, 100, for `u`. The column to the left is the same for the `t`
|
||||||
|
variable.
|
||||||
|
|
||||||
|
Thus it seems that in order to get the generated output correct one needs to
|
||||||
|
provide the correct input in comments or possibly by rearranging some of the
|
||||||
|
code (this was required to make the generated code compile at all when changing
|
||||||
|
the buffer size).
|
||||||
|
|
||||||
|
|
||||||
# 1995
|
# 1995
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user