]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/: Use READLINKNUL() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Wed, 3 Jul 2024 01:21:10 +0000 (03:21 +0200)
committerSerge Hallyn <serge@hallyn.com>
Sat, 2 Nov 2024 02:25:50 +0000 (21:25 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/tcbfuncs.c
lib/user_busy.c

index 3dc2abd700e8e6db1a8cd6481178e015b8c8c328..6971ebe840dd776ab45f727d49bf69bd6e2ba046 100644 (file)
 
 #include "defines.h"
 #include "prototypes.h"
+#include "fs/readlink/readlinknul.h"
 #include "getdef.h"
 #include "shadowio.h"
 #include "tcbfuncs.h"
-
 #include "shadowlog_internal.h"
 
+
 #define SHADOWTCB_HASH_BY 1000
 #define SHADOWTCB_LOCK_SUFFIX ".lock"
 
@@ -96,7 +97,6 @@ static /*@null@*/ char *shadowtcb_path_rel_existing (const char *name)
        char *path, *rval;
        struct stat st;
        char link[8192];
-       ssize_t ret;
 
        if (asprintf (&path, TCB_DIR "/%s", name) == -1) {
                OUT_OF_MEMORY;
@@ -125,8 +125,7 @@ static /*@null@*/ char *shadowtcb_path_rel_existing (const char *name)
                free (path);
                return NULL;
        }
-       ret = readlink (path, link, sizeof (link) - 1);
-       if (-1 == ret) {
+       if (READLINKNUL(path, link) == -1) {
                fprintf (shadow_logfd,
                         _("%s: Cannot read symbolic link %s: %s\n"),
                         shadow_progname, path, strerror (errno));
@@ -134,14 +133,6 @@ static /*@null@*/ char *shadowtcb_path_rel_existing (const char *name)
                return NULL;
        }
        free (path);
-       if ((size_t)ret >= sizeof(link) - 1) {
-               stpcpy(&link[sizeof(link) - 1], "");
-               fprintf (shadow_logfd,
-                        _("%s: Suspiciously long symlink: %s\n"),
-                        shadow_progname, link);
-               return NULL;
-       }
-       stpcpy(&link[ret], "");
        rval = strdup (link);
        if (NULL == rval) {
                OUT_OF_MEMORY;
index 8e80049e726cc1368a000075459217460b50331c..43cff5b0735fbf57234de1c8ca824ce450346bc8 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "atoi/getnum.h"
 #include "defines.h"
+#include "fs/readlink/readlinknul.h"
 #include "prototypes.h"
 #ifdef ENABLE_SUBIDS
 #include "subordinateio.h"
@@ -93,17 +94,16 @@ static int different_namespace (const char *sname)
        /* 41: /proc/xxxxxxxxxx/task/xxxxxxxxxx/ns/user + \0 */
        char     path[41];
        char     buf[512], buf2[512];
-       ssize_t  llen1, llen2;
 
        SNPRINTF(path, "/proc/%s/ns/user", sname);
 
-       if ((llen1 = readlink (path, buf, sizeof(buf))) == -1)
+       if (READLINKNUL(path, buf) == -1)
                return 0;
 
-       if ((llen2 = readlink ("/proc/self/ns/user", buf2, sizeof(buf2))) == -1)
+       if (READLINKNUL("/proc/self/ns/user", buf2) == -1)
                return 0;
 
-       if (llen1 == llen2 && memcmp (buf, buf2, llen1) == 0)
+       if (strcmp(buf, buf2) == 0)
                return 0; /* same namespace */
 
        return 1;