From 965759365d872c32cb0cd297f6cc1b8a68568052 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 7 Apr 2023 10:59:36 -0700 Subject: [PATCH 1/5] Add note about fgets() in 1990/cmills About why it's useful. It's both a problem to keep gets() but it's also potentially a problem to change it to fgets(). But as it will prevent alarming the user with warnings about gets() and also causing messed up output (see below) this is useful. With the original code one will see under macOS something like: $ ./cmills.alt Shuffle... warning: this program uses gets(), which is unsafe. Total $1000. Wager? which is very wrong. I did not delete the cmills.alt.c but perhaps it should be deleted. That can come another time. --- 1990/cmills/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/1990/cmills/README.md b/1990/cmills/README.md index 7aab5822b..1ffc1057d 100644 --- a/1990/cmills/README.md +++ b/1990/cmills/README.md @@ -23,7 +23,8 @@ work in modern systems (it resulted in a bus error otherwise). Thank you Yusuke for your assistance! [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made this safer by -using `fgets()` instead of `gets()`. Thank you Cody! +using `fgets()` instead of `gets()`. This avoids a potentially alarming warning +at linking or runtime. Thank you Cody for your assistance! The original bug fixed version is in [cmills.alt.c](cmills.alt.c), described in the `Alternate code` section. From 58f30bd65e2ecb59d6c75ac4521e40bc0211377e Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 7 Apr 2023 11:02:58 -0700 Subject: [PATCH 2/5] Add note about fgets() in 1990/tbr About why it's useful. It's a problem to keep gets() but it might be a problem to not keep it as well. Nevertheless with macOS the output of the alternative code (which probably should be deleted but this can happen another time) is confusing: $ ./tbr.alt $ warning: this program uses gets(), which is unsafe. [] The [] is the cursor on a blank line. The first line of output of the program (which is not supposed to have a newline) instead has the warning and then a newline appended to it. --- 1990/tbr/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/1990/tbr/README.md b/1990/tbr/README.md index 9724d5aee..9224eb261 100644 --- a/1990/tbr/README.md +++ b/1990/tbr/README.md @@ -23,8 +23,9 @@ make all modern compilers; `exit(3)` returns void but the function was used in a binary expression so this wouldn't even compile. Cody also changed the code to use `fgets()` instead of `gets()` so one would not get a warning about the use of -`gets()` at execution which was interspersed with the output. Thank you Cody for -your assistance! +`gets()` at linking time or execution, the latter case causing confusing output +due to the warning being interspersed with the program's output. Thank you Cody +for your assistance! For the original version with `gets()` see the alternate code section below. From 6186baa8eb541690540b856373d59c35ed1ac268 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 7 Apr 2023 11:06:00 -0700 Subject: [PATCH 3/5] Reword note about fgets() in 1992/adrian --- 1992/adrian/README.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/1992/adrian/README.md b/1992/adrian/README.md index f1ad0b52c..9bc7b26f9 100644 --- a/1992/adrian/README.md +++ b/1992/adrian/README.md @@ -14,16 +14,17 @@ make all [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) changed the location -that it used `gets()` to be `fgets()` instead to make it safer. One might think -that simply changing the gets() to fgets() (with stdin) would work but it did -not because `fgets()` stores the newline and `gets()` does not. The code was -relying on not having this newline. With `fgets()` the code `if(A(Y)) puts(Y);` -ended up printing an extra line which made the generation of some files (like -`adhead.c`) fail to compile (`gets()` does not store the newline but `fgets()` -does). Why? There was a blank line after a `\` at the end of the first line of a -macro definition! Thus the code now first trims off the last character of the -buffer read to get the same correct functionality but in a safe way. Thank you -Cody for your assistance! +that it used `gets()` to be `fgets()` instead to make it safer and to prevent +any warnings during linking or runtime. One might think that simply changing the +gets() to fgets() (with stdin) would work but it did not because `fgets()` +stores the newline and `gets()` does not. The code was relying on not having +this newline. With `fgets()` the code `if(A(Y)) puts(Y);` ended up printing an +extra line which made the generation of some files (like `adhead.c`) fail to +compile (`gets()` does not store the newline but `fgets()` does). Why? There was +a blank line after a `\` at the end of the first line of a macro definition! +Thus the code now first trims off the last character of the buffer read to get +the same correct functionality but in a safe way. Thank you Cody for your +assistance! For the original version [adrian.alt.c](adrian.alt.c) see the `Alternate code` section below. From b9e3cc4357ac6ee62764bcd0326e4bd6a54fae2b Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 7 Apr 2023 11:07:06 -0700 Subject: [PATCH 4/5] Reword note about gets() in 1992/gson --- 1992/gson/README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/1992/gson/README.md b/1992/gson/README.md index bc78dd775..fe90038ae 100644 --- a/1992/gson/README.md +++ b/1992/gson/README.md @@ -16,13 +16,14 @@ [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) changed the buffer size in such a way that gets() should be safe (theoretically) as it comes from the -command line. Ideally `fgets()` would be used but this is a more problematic. +command line (though it can also read input from stdin after starting the +program). Ideally `fgets()` would be used but this is a more problematic. Previously it had a buffer size of 256 which could easily overflow. In this entry `gets()` is used in a more complicated way: first `m` is set to `*++p` in a for loop where `p` is argv. Later `m` is set to point to `h` which was of size -\256. `gets()` is called as `m = gets(m)`) but trying to change it to use fgets() -proved more a problem. Since the input must come from the command line Cody -changed the buffer size to `ARG_MAX+1` which should be enough (again +\256. `gets()` is called as `m = gets(m)`) but trying to change it to use +fgets() proved more a problem. Since the input must come from the command line +Cody changed the buffer size to `ARG_MAX+1` which should be enough (again theoretically) especially since the command expects redirecting a dictionary file as part of the command line. This also makes it possible for longer strings to be read (in case the `gets()` was not used in a loop). Thank you Cody for From 4fbc411535f66908b60ebb9231cb236fb4450dc4 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Fri, 7 Apr 2023 11:08:02 -0700 Subject: [PATCH 5/5] Add note about alt code of 1992/lush (gets()) This code should probably be deleted but that can happen another time. This can be considered a reminder to do this when I have the time. --- 1992/lush/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1992/lush/README.md b/1992/lush/README.md index 287987eab..8b93a22ff 100644 --- a/1992/lush/README.md +++ b/1992/lush/README.md @@ -28,7 +28,7 @@ code` section below. ### Alternate code: -The original source (fixed to work with gcc) which uses gets() try: +For the original source (fixed to work with gcc) which uses gets() try: ```sh make alt