]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Use strrspn() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Sat, 18 May 2024 19:38:24 +0000 (21:38 +0200)
committerSerge Hallyn <serge@hallyn.com>
Wed, 3 Jul 2024 15:03:12 +0000 (10:03 -0500)
This requires changing isspace(3) calls to an explicit accept string,
and I chose " \t\n" for it (as is done in other parts of this project),
which isn't exactly the same, but we probably don't want other
isspace(3) characters in those files, so it should work.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/fields.c
lib/getdef.c
src/login_nopam.c
src/suauth.c

index 539292485dda8a9293448437bde81acfd45c2119..b6d2fa14e66b52835a8da53c889412c1d0d5c8a0 100644 (file)
 #include <ctype.h>
 #include <string.h>
 #include <stdio.h>
+
 #include "prototypes.h"
+#include "string/strchr/strrspn.h"
+
 
 /*
  * valid_field - insure that a field contains all legal characters
@@ -89,11 +92,7 @@ void change_field (char *buf, size_t maxsize, const char *prompt)
                 * makes it possible to change the field to empty, by
                 * entering a space.  --marekm
                 */
-
-               while (newf < cp && isspace (cp[-1])) {
-                       cp--;
-               }
-               *cp = '\0';
+               *strrspn(newf, " \t\n") = '\0';
 
                cp = newf;
                while (isspace (*cp)) {
index 459fdc99c24e1e312a38ce306f5e58a346bb3213..91f40702f09117c305c6d1a586a86315ea1a81a1 100644 (file)
@@ -31,6 +31,7 @@
 #include "string/sprintf/xasprintf.h"
 #include "string/strchr/stpcspn.h"
 #include "string/strchr/stpspn.h"
+#include "string/strchr/strrspn.h"
 
 
 /*
@@ -528,7 +529,6 @@ static void def_load (void)
 #else /* USE_ECONF */
 static void def_load (void)
 {
-       int i;
        FILE *fp;
        char buf[1024], *name, *value, *s;
 
@@ -560,13 +560,7 @@ static void def_load (void)
                /*
                 * Trim trailing whitespace.
                 */
-               for (i = (ptrdiff_t) strlen (buf) - 1; i >= 0; --i) {
-                       if (!isspace (buf[i])) {
-                               break;
-                       }
-               }
-               i++;
-               buf[i] = '\0';
+               *strrspn(buf, " \t\n") = '\0';
 
                /*
                 * Break the line into two fields.
index 1a2b17367f89f5b38f45e2f28fe1dc9dada7f110..03a2871f4d40f28735e38fae5385e72aba7ee2b7 100644 (file)
@@ -57,6 +57,7 @@
 #include <arpa/inet.h>         /* for inet_ntoa() */
 
 #include "sizeof.h"
+#include "string/strchr/strrspn.h"
 
 #if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 64)
 #undef MAXHOSTNAMELEN
@@ -110,10 +111,7 @@ int login_access (const char *user, const char *from)
                        if (line[0] == '#') {
                                continue;       /* comment line */
                        }
-                       while (end > 0 && isspace (line[end - 1])) {
-                               end--;
-                       }
-                       line[end] = '\0';       /* strip trailing whitespace */
+                       *strrspn(line, " \t\n") = '\0';
                        if (line[0] == '\0') {  /* skip blank lines */
                                continue;
                        }
index 4d631904dcf0846a614d35194a49846069f804b9..ed45a8564241255858c72fb43993c67e31eafd50 100644 (file)
@@ -8,13 +8,17 @@
  */
 
 #include <config.h>
+
 #include <errno.h>
 #include <grp.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <sys/types.h>
+
 #include "defines.h"
 #include "prototypes.h"
+#include "string/strchr/strrspn.h"
+
 
 #ifndef SUAUTHFILE
 #define SUAUTHFILE "/etc/suauth"
@@ -77,11 +81,7 @@ int check_su_auth (const char *actual_id,
                        continue;
                }
 
-               while (endline > 0 && (temp[endline - 1] == ' '
-                                      || temp[endline - 1] == '\t'
-                                      || temp[endline - 1] == '\n'))
-                       endline--;
-               temp[endline] = '\0';
+               *strrspn(temp, " \t\n") = '\0';
 
                posn = 0;
                while (temp[posn] == ' ' || temp[posn] == '\t')