From: Alejandro Colomar Date: Wed, 3 Jul 2024 01:21:10 +0000 (+0200) Subject: lib/: Use READLINKNUL() instead of its pattern X-Git-Tag: 4.17.0-rc1~40 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=f8c7955bbbd086aa086d4b61f3a0b100befe4258;p=thirdparty%2Fshadow.git lib/: Use READLINKNUL() instead of its pattern Signed-off-by: Alejandro Colomar --- diff --git a/lib/tcbfuncs.c b/lib/tcbfuncs.c index 3dc2abd70..6971ebe84 100644 --- a/lib/tcbfuncs.c +++ b/lib/tcbfuncs.c @@ -19,12 +19,13 @@ #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; diff --git a/lib/user_busy.c b/lib/user_busy.c index 8e80049e7..43cff5b07 100644 --- a/lib/user_busy.c +++ b/lib/user_busy.c @@ -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;