]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Use fgets_a() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Mon, 12 Aug 2024 01:24:48 +0000 (03:24 +0200)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Mon, 16 Mar 2026 11:12:58 +0000 (12:12 +0100)
Except for the updated includes, this patch has been scripted with a
semantic patch:

$ cat ~/tmp/spatch/fgets_fgets_a.sp
@@
expression a, b;
@@

- fgets(a, countof(a), b)
+ fgets_a(a, b)

Applied as:

$ find lib* src -type f \
| xargs spatch --sp-file ~/tmp/spatch/fgets_fgets_a.sp --in-place;

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
17 files changed:
lib/console.c
lib/fields.c
lib/getdef.c
lib/hushed.c
lib/limits.c
lib/loginprompt.c
lib/port.c
lib/setupenv.c
lib/ttytype.c
lib/tz.c
lib/user_busy.c
src/chgpasswd.c
src/chpasswd.c
src/login_nopam.c
src/newusers.c
src/suauth.c
src/useradd.c

index 12f32be24d5fa34d58c52c7e2e00c591067c9b2d..9df3e2a49eb8781a49b67bb75c359c000993d1ac 100644 (file)
@@ -15,8 +15,8 @@
 
 #include "defines.h"
 #include "getdef.h"
+#include "io/fgets/fgets.h"
 #include "prototypes.h"
-#include "sizeof.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
 #include "string/strcpy/strtcpy.h"
@@ -77,7 +77,7 @@ is_listed(const char *cfgin, const char *tty, bool def)
         * See if this tty is listed in the console file.
         */
 
-       while (fgets(buf, countof(buf), fp) != NULL) {
+       while (fgets_a(buf, fp) != NULL) {
                stpsep(buf, "\n");
                if (streq(buf, tty)) {
                        (void) fclose (fp);
index f416b54f80c645c1f9e99198b222ef5f66960f4e..759dea755f981c6ec46eb02d8b3fd77e370352da 100644 (file)
@@ -17,8 +17,8 @@
 #include <string.h>
 #include <sys/param.h>
 
+#include "io/fgets/fgets.h"
 #include "prototypes.h"
-#include "sizeof.h"
 #include "string/ctype/strisascii/strisprint.h"
 #include "string/ctype/strchrisascii/strchriscntrl.h"
 #include "string/strcmp/streq.h"
@@ -67,7 +67,7 @@ change_field(char *buf, size_t maxsize, const char *prompt)
 
        printf ("\t%s [%s]: ", prompt, buf);
        (void) fflush (stdout);
-       if (fgets(newf, countof(newf), stdin) == NULL)
+       if (fgets_a(newf, stdin) == NULL)
                return;
 
        if (stpsep(newf, "\n") == NULL)
index c850ac4f51bd7a8df91f15ae5aaeafeada8a5ac5..3a9a423ceb80bd23a63c05131a778fe06145f4b1 100644 (file)
@@ -25,6 +25,7 @@
 #include "atoi/a2i.h"
 #include "defines.h"
 #include "getdef.h"
+#include "io/fgets/fgets.h"
 #include "prototypes.h"
 #include "shadowlog.h"
 #include "sizeof.h"
@@ -550,7 +551,7 @@ static void def_load (void)
        /*
         * Go through all of the lines in the file.
         */
-       while (fgets(buf, countof(buf), fp) != NULL) {
+       while (fgets_a(buf, fp) != NULL) {
 
                /*
                 * Trim trailing whitespace.
index 1de80f5daf4f44a817b1b4738b8d47d8404d0469..1b1fc40a2ec33922ed3493cf469fa5ae7bd6a844 100644 (file)
@@ -20,8 +20,8 @@
 
 #include "defines.h"
 #include "getdef.h"
+#include "io/fgets/fgets.h"
 #include "prototypes.h"
-#include "sizeof.h"
 #include "string/sprintf/snprintf.h"
 #include "string/strcmp/streq.h"
 #include "string/strtok/stpsep.h"
@@ -75,7 +75,7 @@ bool hushed (const char *username)
        if (NULL == fp) {
                return false;
        }
-       for (found = false; !found && (fgets(buf, countof(buf), fp) != NULL);) {
+       for (found = false; !found && (fgets_a(buf, fp) != NULL);) {
                stpsep(buf, "\n");
                found = streq(buf, pw->pw_shell) ||
                        streq(buf, pw->pw_name);
index f4244a52d5fd7e8ce30d33192a55459707423a80..129a99fd75f1f4a4a12a15652e870081784abb2a 100644 (file)
@@ -31,7 +31,7 @@
 #include <sys/resource.h>
 
 #include "atoi/a2i.h"
-#include "sizeof.h"
+#include "io/fgets/fgets.h"
 #include "string/memset/memzero.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
@@ -362,7 +362,7 @@ static int setup_user_limits (const char *uname)
         *
         * FIXME: a better (smarter) checking should be done
         */
-       while (fgets(buf, countof(buf), fil) != NULL) {
+       while (fgets_a(buf, fil) != NULL) {
                if (strprefix(buf, "#") || strprefix(buf, "\n")) {
                        continue;
                }
index 6a2046065a765269fd04e0cfe870249113f74dd1..9eeae3ddb03722719626a9ff27f388119f89d3fc 100644 (file)
@@ -16,8 +16,8 @@
 #include "attr.h"
 #include "defines.h"
 #include "getdef.h"
+#include "io/fgets/fgets.h"
 #include "prototypes.h"
-#include "sizeof.h"
 #include "string/memset/memzero.h"
 #include "string/strcpy/strtcpy.h"
 #include "string/strspn/stpspn.h"
@@ -83,7 +83,7 @@ login_prompt(char *name, int namesize)
         */
 
        memzero_a(buf);
-       if (fgets(buf, countof(buf), stdin) == NULL)
+       if (fgets_a(buf, stdin) == NULL)
                exit (EXIT_FAILURE);
 
        if (stpsep(buf, "\n") == NULL)
index 565054d24983f7cdbaa8871fba6be964e384cf81..8cf6f39fb9f87c395364f6ff9e4f4d8f66938bbd 100644 (file)
@@ -17,9 +17,9 @@
 #include <string.h>
 
 #include "defines.h"
+#include "io/fgets/fgets.h"
 #include "port.h"
 #include "prototypes.h"
-#include "sizeof.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
 #include "string/strtok/stpsep.h"
@@ -140,7 +140,7 @@ getportent(void)
         */
 
 next:
-       if (fgets(buf, countof(buf), ports) == NULL) {
+       if (fgets_a(buf, ports) == NULL) {
                errno = saveerr;
                return NULL;
        }
index 5e36bcf67567302fe579259697b5c014740b8ca0..efa0f2d820a4683fa9424a6c21046effd70d2bf6 100644 (file)
 
 #include "config.h"
 
+#include <ctype.h>
+#include <pwd.h>
 #include <stddef.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
-#include <ctype.h>
 
 #include "prototypes.h"
 #include "defines.h"
-#include <pwd.h>
 #include "getdef.h"
+#include "io/fgets/fgets.h"
 #include "shadowlog.h"
-#include "sizeof.h"
 #include "string/sprintf/aprintf.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
@@ -54,7 +54,7 @@ static void read_env_file (const char *filename)
        if (NULL == fp) {
                return;
        }
-       while (fgets(buf, countof(buf), fp) != NULL) {
+       while (fgets_a(buf, fp) != NULL) {
                if (stpsep(buf, "\n") == NULL)
                        break;
 
index 9fb046e0a9b016bf625e793f4e52dc288c575f57..e2a9c98f7db16311b3e250bfc1d82182419cd4e3 100644 (file)
@@ -17,8 +17,8 @@
 
 #include "defines.h"
 #include "getdef.h"
+#include "io/fgets/fgets.h"
 #include "prototypes.h"
-#include "sizeof.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
 #include "string/strtok/stpsep.h"
@@ -49,7 +49,7 @@ void ttytype (const char *line)
                        perror (typefile);
                return;
        }
-       while (fgets(buf, countof(buf), fp) != NULL) {
+       while (fgets_a(buf, fp) != NULL) {
                if (strprefix(buf, "#")) {
                        continue;
                }
index 9e530a921cbe991135df28296bad5b800ece637a..b2d9531e2059e0a56a8395d77f115f5967c317af 100644 (file)
--- a/lib/tz.c
+++ b/lib/tz.c
@@ -19,8 +19,8 @@
 
 #include "defines.h"
 #include "getdef.h"
+#include "io/fgets/fgets.h"
 #include "prototypes.h"
-#include "sizeof.h"
 #include "string/strtok/stpsep.h"
 
 
@@ -38,7 +38,7 @@
 
        fp = fopen (fname, "r");
        if (   (NULL == fp)
-           || (fgets(tzbuf, countof(tzbuf), fp) == NULL)) {
+           || (fgets_a(tzbuf, fp) == NULL)) {
                result = "TZ=CST6CDT";
        } else {
                stpsep(tzbuf, "\n");
index 8cf5c8937b56e772094f382e2105c7d6eeccc0c7..c2a1829f8e45193d995117c1dc8a63c7a45679a3 100644 (file)
 #include "atoi/getnum.h"
 #include "defines.h"
 #include "fs/readlink/readlinknul.h"
+#include "io/fgets/fgets.h"
 #include "prototypes.h"
 #ifdef ENABLE_SUBIDS
 #include "subordinateio.h"
 #endif                         /* ENABLE_SUBIDS */
 #include "shadowlog.h"
-#include "sizeof.h"
 #include "string/sprintf/snprintf.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strneq.h"
@@ -129,7 +129,7 @@ static int check_status (const char *name, const char *sname, uid_t uid)
        if (NULL == sfile) {
                return 0;
        }
-       while (fgets(line, countof(line), sfile) != NULL) {
+       while (fgets_a(line, sfile) != NULL) {
                if (strprefix(line, "Uid:\t")) {
                        unsigned long ruid, euid, suid;
 
index 1430a48b2a760edbcc240c82c1b13aeb1e5df58d..e77ecc6ac7f284d26d5f0f2d34135c5fcb638e51 100644 (file)
@@ -29,9 +29,9 @@
 #endif
 /*@-exitarg@*/
 #include "exitcodes.h"
+#include "io/fgets/fgets.h"
 #include "shadow/gshadow/sgrp.h"
 #include "shadowlog.h"
-#include "sizeof.h"
 #include "string/strcmp/streq.h"
 #include "string/strerrno.h"
 #include "string/strtok/stpsep.h"
@@ -384,7 +384,7 @@ int main (int argc, char **argv)
         * group entry for each group will be looked up in the appropriate
         * file (gshadow or group) and the password changed.
         */
-       while (fgets(buf, countof(buf), stdin) != NULL) {
+       while (fgets_a(buf, stdin) != NULL) {
                line++;
                if (stpsep(buf, "\n") == NULL) {
                        fprintf (stderr, _("%s: line %jd: line too long\n"),
index 9d865ba3c79f969968bd95110a177b6e4d05b72c..fa0b19d15f6e501491856beae2d8587a182ea6b3 100644 (file)
@@ -33,8 +33,8 @@
 #include "shadowio.h"
 /*@-exitarg@*/
 #include "exitcodes.h"
+#include "io/fgets/fgets.h"
 #include "shadowlog.h"
-#include "sizeof.h"
 #include "string/strcmp/streq.h"
 #include "string/strerrno.h"
 #include "string/strtok/stpsep.h"
@@ -424,14 +424,14 @@ int main (int argc, char **argv)
         * last change date is set in the age only if aging information is
         * present.
         */
-       while (fgets(buf, countof(buf), stdin) != NULL) {
+       while (fgets_a(buf, stdin) != NULL) {
                char  *cp;
 
                line++;
                if (stpsep(buf, "\n") == NULL) {
                        if (feof (stdin) == 0) {
                                // Drop all remaining characters on this line.
-                               while (fgets(buf, countof(buf), stdin) != NULL) {
+                               while (fgets_a(buf, stdin) != NULL) {
                                        if (strchr(buf, '\n'))
                                                break;
                                }
index 4890a9a4fcc2116dd9b5465a12c962b6b939f297..3269e74f74783f78408ef397a4eeceba704e6624 100644 (file)
@@ -58,6 +58,7 @@
 #include <unistd.h>
 
 #include "defines.h"
+#include "io/fgets/fgets.h"
 #include "prototypes.h"
 #include "sizeof.h"
 #include "string/strcmp/strcaseeq.h"
@@ -100,7 +101,7 @@ login_access(const char *user, const char *from)
        if (NULL != fp) {
                intmax_t lineno = 0;    /* for diagnostics */
                while (   !match
-                      && (fgets(line, countof(line), fp) != NULL))
+                      && (fgets_a(line, fp) != NULL))
                {
                        char  *p;
 
index f079bc837f620d25df98643f967271fae1f00920..25f0841eba64be80ae161f496b92037878608b6e 100644 (file)
@@ -40,6 +40,7 @@
 #include "defines.h"
 #include "getdef.h"
 #include "groupio.h"
+#include "io/fgets/fgets.h"
 #include "nscd.h"
 #include "prototypes.h"
 #include "pwio.h"
@@ -50,7 +51,6 @@
 #endif                         /* ENABLE_SUBIDS */
 #include "shadow/gshadow/sgrp.h"
 #include "shadowlog.h"
-#include "sizeof.h"
 #include "sssd.h"
 #include "string/sprintf/snprintf.h"
 #include "string/strcmp/streq.h"
@@ -1022,7 +1022,7 @@ int main (int argc, char **argv)
         * over 100 is allocated. The pw_gid field will be updated with that
         * value.
         */
-       while (fgets(buf, countof(buf), stdin) != NULL) {
+       while (fgets_a(buf, stdin) != NULL) {
                line++;
                if (stpsep(buf, "\n") == NULL && feof(stdin) == 0) {
                        fprintf (stderr, _("%s: line %jd: line too long\n"),
index 935f2637af60dccb556c1efc91428e6562e8c462..5d55484ce95458b2e818e1fdbc29fcc2fa75cd01 100644 (file)
@@ -18,8 +18,8 @@
 #include <sys/types.h>
 
 #include "defines.h"
+#include "io/fgets/fgets.h"
 #include "prototypes.h"
-#include "sizeof.h"
 #include "string/strcmp/streq.h"
 #include "string/strcmp/strprefix.h"
 #include "string/strspn/stpspn.h"
@@ -73,7 +73,7 @@ check_su_auth(const char *actual_id, const char *wanted_id, bool su_to_root)
                return DENY;
        }
 
-       while (fgets(temp, countof(temp), authfile_fd) != NULL) {
+       while (fgets_a(temp, authfile_fd) != NULL) {
                char  *p;
 
                lines++;
index de75fb0e8ffcee47bc3d1601d9b1d458864b7dc3..41ef0769168d7b471e2383e157f1555f6161de15 100644 (file)
@@ -39,6 +39,7 @@
 #include "fs/mkstemp/fmkomstemp.h"
 #include "getdef.h"
 #include "groupio.h"
+#include "io/fgets/fgets.h"
 #include "nscd.h"
 #include "prototypes.h"
 #include "pwauth.h"
@@ -59,7 +60,6 @@
 #endif
 #include "shadow/gshadow/sgrp.h"
 #include "shadowlog.h"
-#include "sizeof.h"
 #include "sssd.h"
 #include "string/memset/memzero.h"
 #include "string/sprintf/aprintf.h"
@@ -355,7 +355,7 @@ get_defaults(const struct option_flags *flags)
         * Read the file a line at a time. Only the lines that have relevant
         * values are used, everything else can be ignored.
         */
-       while (fgets(buf, countof(buf), fp) != NULL) {
+       while (fgets_a(buf, fp) != NULL) {
                stpsep(buf, "\n");
 
                cp = stpsep(buf, "=");
@@ -599,7 +599,7 @@ set_defaults(void)
                goto skip;
        }
 
-       while (fgets(buf, countof(buf), ifp) != NULL) {
+       while (fgets_a(buf, ifp) != NULL) {
                char  *val;
 
                if (stpsep(buf, "\n") == NULL) {