From: Alejandro Colomar Date: Mon, 12 Aug 2024 01:24:48 +0000 (+0200) Subject: lib/, src/: Use fgets_a() instead of its pattern X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f94e256673d7d6256c0e45e470687ea17bf4c753;p=thirdparty%2Fshadow.git lib/, src/: Use fgets_a() instead of its pattern 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 Signed-off-by: Alejandro Colomar --- diff --git a/lib/console.c b/lib/console.c index 12f32be24..9df3e2a49 100644 --- a/lib/console.c +++ b/lib/console.c @@ -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); diff --git a/lib/fields.c b/lib/fields.c index f416b54f8..759dea755 100644 --- a/lib/fields.c +++ b/lib/fields.c @@ -17,8 +17,8 @@ #include #include +#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) diff --git a/lib/getdef.c b/lib/getdef.c index c850ac4f5..3a9a423ce 100644 --- a/lib/getdef.c +++ b/lib/getdef.c @@ -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. diff --git a/lib/hushed.c b/lib/hushed.c index 1de80f5da..1b1fc40a2 100644 --- a/lib/hushed.c +++ b/lib/hushed.c @@ -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); diff --git a/lib/limits.c b/lib/limits.c index f4244a52d..129a99fd7 100644 --- a/lib/limits.c +++ b/lib/limits.c @@ -31,7 +31,7 @@ #include #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; } diff --git a/lib/loginprompt.c b/lib/loginprompt.c index 6a2046065..9eeae3ddb 100644 --- a/lib/loginprompt.c +++ b/lib/loginprompt.c @@ -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) diff --git a/lib/port.c b/lib/port.c index 565054d24..8cf6f39fb 100644 --- a/lib/port.c +++ b/lib/port.c @@ -17,9 +17,9 @@ #include #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; } diff --git a/lib/setupenv.c b/lib/setupenv.c index 5e36bcf67..efa0f2d82 100644 --- a/lib/setupenv.c +++ b/lib/setupenv.c @@ -13,18 +13,18 @@ #include "config.h" +#include +#include #include #include #include #include -#include #include "prototypes.h" #include "defines.h" -#include #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; diff --git a/lib/ttytype.c b/lib/ttytype.c index 9fb046e0a..e2a9c98f7 100644 --- a/lib/ttytype.c +++ b/lib/ttytype.c @@ -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; } diff --git a/lib/tz.c b/lib/tz.c index 9e530a921..b2d9531e2 100644 --- 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"); diff --git a/lib/user_busy.c b/lib/user_busy.c index 8cf5c8937..c2a1829f8 100644 --- a/lib/user_busy.c +++ b/lib/user_busy.c @@ -20,12 +20,12 @@ #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; diff --git a/src/chgpasswd.c b/src/chgpasswd.c index 1430a48b2..e77ecc6ac 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -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"), diff --git a/src/chpasswd.c b/src/chpasswd.c index 9d865ba3c..fa0b19d15 100644 --- a/src/chpasswd.c +++ b/src/chpasswd.c @@ -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; } diff --git a/src/login_nopam.c b/src/login_nopam.c index 4890a9a4f..3269e74f7 100644 --- a/src/login_nopam.c +++ b/src/login_nopam.c @@ -58,6 +58,7 @@ #include #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; diff --git a/src/newusers.c b/src/newusers.c index f079bc837..25f0841eb 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -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"), diff --git a/src/suauth.c b/src/suauth.c index 935f2637a..5d55484ce 100644 --- a/src/suauth.c +++ b/src/suauth.c @@ -18,8 +18,8 @@ #include #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++; diff --git a/src/useradd.c b/src/useradd.c index de75fb0e8..41ef07691 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -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) {