]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Use strprefix() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Tue, 10 Dec 2024 03:58:12 +0000 (04:58 +0100)
committerSerge Hallyn <serge@hallyn.com>
Mon, 26 May 2025 16:29:26 +0000 (11:29 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/copydir.c
lib/env.c
src/newgidmap.c
src/userdel.c

index 6312399e5b3395f8aec2ecf1ccd64935a288ed04..3a6c132b582bb95ab03cf2585bcec9b1a1cf0ef2 100644 (file)
@@ -40,6 +40,7 @@
 #include "shadowlog.h"
 #include "string/sprintf/xasprintf.h"
 #include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
 
 
 static /*@null@*/const char *src_orig;
@@ -576,7 +577,7 @@ static int copy_symlink (const struct path_info *src, const struct path_info *ds
         * create a link to the corresponding entry in the dst_orig
         * directory.
         */
-       if (strncmp(oldlink, src_orig, strlen(src_orig)) == 0) {
+       if (strprefix(oldlink, src_orig)) {
                char  *dummy;
 
                xasprintf(&dummy, "%s%s", dst_orig, oldlink + strlen(src_orig));
index 9cb3137122b8d1322ec7d6b9a592a479ea35c20e..df1a2c08a78f26260d598e72286d379f8d64e769 100644 (file)
--- a/lib/env.c
+++ b/lib/env.c
@@ -23,6 +23,7 @@
 #include "shadowlog.h"
 #include "string/sprintf/snprintf.h"
 #include "string/sprintf/xasprintf.h"
+#include "string/strcmp/strprefix.h"
 #include "string/strdup/xstrdup.h"
 
 
@@ -175,7 +176,7 @@ void set_env (int argc, char *const *argv)
                        const char *const *p;
 
                        for (p = forbid; NULL != *p; p++) {
-                               if (strncmp (*argv, *p, strlen (*p)) == 0) {
+                               if (strprefix(*argv, *p)) {
                                        break;
                                }
                        }
@@ -210,7 +211,7 @@ void sanitize_env (void)
 
        for (cur = envp; NULL != *cur; cur++) {
                for (bad = forbid; NULL != *bad; bad++) {
-                       if (strncmp (*cur, *bad, strlen (*bad)) == 0) {
+                       if (strprefix(*cur, *bad)) {
                                for (move = cur; NULL != *move; move++) {
                                        *move = *(move + 1);
                                }
index 863c5fb662be5f96ea0dc9454047961dcabb0cea..53c401e75ec88d2fab4d2d77aca92e6049c15a68 100644 (file)
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+
 #include "defines.h"
-#include "prototypes.h"
-#include "subordinateio.h"
 #include "getdef.h"
 #include "idmapping.h"
+#include "prototypes.h"
 #include "shadowlog.h"
+#include "string/strcmp/strprefix.h"
+#include "subordinateio.h"
+
 
 /*
  * Global variables
@@ -116,7 +119,7 @@ static void write_setgroups(int proc_dir_fd, bool allow_setgroups)
                        strerror(errno));
                exit(EXIT_FAILURE);
        }
-       if (!strncmp(policy_buffer, policy, strlen(policy)))
+       if (strprefix(policy_buffer, policy))
                goto out;
 
        /* Write the policy. */
index c034afbc199af1b8182ee6f12d4fe2762f76ee51..6bc4074bc41de7292d13648c4d5ca76a2e6c28b0 100644 (file)
@@ -53,6 +53,7 @@
 #include "shadowlog.h"
 #include "string/sprintf/xasprintf.h"
 #include "string/strcmp/streq.h"
+#include "string/strcmp/strprefix.h"
 #include "string/strdup/xstrdup.h"
 
 
@@ -701,7 +702,7 @@ static void user_cancel (const char *user)
 #ifdef EXTRA_CHECK_HOME_DIR
 static bool path_prefix (const char *s1, const char *s2)
 {
-       return (   (strncmp (s2, s1, strlen (s1)) == 0)
+       return (   strprefix(s2, s1)
                && (   ('\0' == s2[strlen (s1)])
                    || ('/'  == s2[strlen (s1)])));
 }