From 89860e7b71479b6f239da8d7e69fa08e38b93262 Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Mon, 3 Apr 2023 12:29:51 -0700 Subject: [PATCH] Clarify gets()/fgets()/ARG_MAX in 1992/gson By accident I stated that I changed this entry to not use gets() but instead fgets(). This is unfortunately not true because of the way gets() is used. I have now made it (I hope) a bit clearer. I also pointed out that it's theoretically safe. Since it uses gets() which comes from stdin ARG_MAX should be relevant. Thus I made the buffer size ARG_MAX+1. But something I am not so clear on is whether or not ARG_MAX is the entire command line or a single argument. Looking did not help here as some say one thing and others say the other. Doing xargs --show-limits and also checking the value of ARG_MAX suggests that it's for the entire command but I don't know for sure of that. Nevertheless it is safer than it was if not completely safe. --- 1992/gson/README.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/1992/gson/README.md b/1992/gson/README.md index c11cfc6fe..666b6b38c 100644 --- a/1992/gson/README.md +++ b/1992/gson/README.md @@ -14,16 +14,19 @@ ./ag word word2 word3 < /path/to/dictionary -[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this entry to not -use gets(). Previously it had a buffer size of 256 which could easily overflow. -Now 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 and then later `m` is set to point to -`h` which is of size 256) and 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 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 your assistance! +[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. +Previously it had a buffer size of 256 which could easily overflow. Now 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 and then later `m` is set to point to `h` which is +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 +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 +your assistance! ## Judges' comment: