commit 77f7f5ed8370cf11b8992c70e7f5361625b9afa9
parent d0a78b16bdbd4330424b9abdcf6448c5a2b42253
Author: KatolaZ <katolaz@freaknet.org>
Date: Sat, 3 Dec 2022 14:18:29 +0000
fix realpath when base is a symlink
Signed-off-by: Christoph Lohmann <20h@r-36.net>
Diffstat:
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/ind.c b/ind.c
@@ -415,7 +415,7 @@ scanfile(char *fname)
int
printelem(int fd, Elems *el, char *file, char *base, char *addr, char *port)
{
- char *path, *p, *argbase, buf[PATH_MAX+1], *argp;
+ char *path, *p, *argbase, buf[PATH_MAX+1], *argp, *realbase;
int len, blen;
if (!strcmp(el->e[3], "server")) {
@@ -461,9 +461,11 @@ printelem(int fd, Elems *el, char *file, char *base, char *addr, char *port)
snprintf(buf, sizeof(buf), "%s%.*s/%.*s", base, len,
path, blen, el->e[2]);
+
if ((path = realpath(buf, NULL)) &&
- !strncmp(base, path, strlen(base))) {
- p = path + strlen(base);
+ (realbase = realpath(base, NULL)) &&
+ !strncmp(realbase, path, strlen(realbase))) {
+ p = path + strlen(realbase);
/*
* Do not forget to readd arguments which were
@@ -476,6 +478,7 @@ printelem(int fd, Elems *el, char *file, char *base, char *addr, char *port)
free(el->e[2]);
el->e[2] = argp;
+ free(realbase);
}
free(path);
}