lib/: Use READLINKNUL() instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
5d5ab18890
commit
f8c7955bbb
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user