commit 02f139afd2bbb549ede10fbe7d9f861da7c7ed07
parent 3e208ec5d6049499297023d1edf9da0bcf5ffdf8
Author: Santtu Lakkala <inz@inz.fi>
Date: Mon, 17 May 2021 01:14:38 +0300
Don't use realpath()
Diffstat:
M | main.c | | | 24 | +++++++++++++++++------- |
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/main.c b/main.c
@@ -439,7 +439,8 @@ static char *cleanup_path(char *path, char **basename, size_t *pathlen)
if (r == *pathlen) {
*pathlen = 0;
- *basename = path;
+ if (basename)
+ *basename = path;
return path;
}
@@ -474,10 +475,12 @@ static char *cleanup_path(char *path, char **basename, size_t *pathlen)
path[w++] = path[r++];
}
- if (np)
- *basename = path + parts[np - 1];
- else
- *basename = path;
+ if (basename) {
+ if (np)
+ *basename = path + parts[np - 1];
+ else
+ *basename = path;
+ }
if (w && path[w - 1] == '/')
w--;
@@ -1492,8 +1495,15 @@ int main (int argc, char *argv[])
croak("setuid failed");
}
- if (*gopherroot != '/')
- gopherroot = realpath(gopherroot, gopherrootbuf);
+ if (*gopherroot != '/' && getcwd(gopherrootbuf, sizeof(gopherrootbuf))) {
+ size_t l = strlen(gopherrootbuf);
+ int ll = snprintf(gopherrootbuf + l, sizeof(gopherrootbuf) - l, "/%s", gopherroot);
+ if ((l += ll - 1) < sizeof(gopherrootbuf) - 1 && cleanup_path(gopherrootbuf + 1, NULL, &l)) {
+ gopherrootbuf[l + 1] = '\0';
+ gopherroot = gopherrootbuf;
+ }
+
+ }
if (dofork) {
if (fork()) {