From a3db9ad8f8eb79a931f0bc6d087ca3b52de3dd62 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 13 Mar 2022 17:34:07 -0700 Subject: [PATCH] pathcanon: remove 'flags' argument This function was only ever called with `0` as `flags`, which disables a lot of its logic. We can reduce the amount of ongoing code to maintain by paring this back to just the core in use. --- lib/ast/ast.h | 5 --- lib/ast/pathaccess.c | 4 +-- lib/ast/pathcanon.c | 77 +++----------------------------------------- 3 files changed, 6 insertions(+), 80 deletions(-) diff --git a/lib/ast/ast.h b/lib/ast/ast.h index c6595850a..02f0a8522 100644 --- a/lib/ast/ast.h +++ b/lib/ast/ast.h @@ -22,11 +22,6 @@ extern "C" { #define PATH_MAX 1024 #endif -#define PATH_PHYSICAL 01 -#define PATH_DOTDOT 02 -#define PATH_EXISTS 04 -#define PATH_VERIFIED(n) (((n)&01777)<<5) - #define PATH_REGULAR 010 #define PATH_EXECUTE 001 #define PATH_READ 004 diff --git a/lib/ast/pathaccess.c b/lib/ast/pathaccess.c index c7c63dd48..5e1f64c52 100644 --- a/lib/ast/pathaccess.c +++ b/lib/ast/pathaccess.c @@ -28,7 +28,7 @@ #include #include -char *pathcanon(char *path, int flags); +char *pathcanon(char *path); char *pathaccess(char *path, const char *dirs, const char *a, const char *b, int mode) @@ -57,7 +57,7 @@ char *pathaccess(char *path, const char *dirs, } do { dirs = pathcat(path, dirs, sep, a, b); - pathcanon(path, 0); + pathcanon(path); if (!access(path, m)) { if ((mode & PATH_REGULAR) && (stat(path, &st) || S_ISDIR(st.st_mode))) diff --git a/lib/ast/pathcanon.c b/lib/ast/pathcanon.c index d75568fdd..2a5334cdb 100644 --- a/lib/ast/pathcanon.c +++ b/lib/ast/pathcanon.c @@ -19,34 +19,18 @@ * move ..'s to the front * /.. preserved (for pdu and newcastle hacks) * FS_3D handles ... - * if (flags&PATH_PHYSICAL) then symlinks resolved at each component - * if (flags&PATH_DOTDOT) then each .. checked for access - * if (flags&PATH_EXISTS) then path must exist at each component - * if (flags&PATH_VERIFIED(n)) then first n chars of path exist - * - * longer pathname possible if (flags&PATH_PHYSICAL) or FS_3D ... involved - * 0 returned on error and if (flags&(PATH_DOTDOT|PATH_EXISTS)) then path - * will contain the components following the failure point */ #include #include #include -#include -#include -#include -#include -char *pathcanon(char *path, int flags) -{ - char *p; +char *pathcanon(char *path) { char *r; char *s; char *t; int dots; char *phys; - char *v; - char* e = path + PATH_MAX; int loop; int oerrno; #if defined(FS_3D) @@ -56,12 +40,12 @@ char *pathcanon(char *path, int flags) oerrno = errno; dots = loop = 0; phys = path; - v = path + ((flags >> 5) & 01777); + (void)phys; if (*path == '/' && *(path + 1) == '/') do path++; while (*path == '/' && *(path + 1) == '/'); - p = r = s = t = path; + r = s = t = path; for (;;) switch (*t++ = *s++) { case '.': @@ -77,17 +61,6 @@ char *pathcanon(char *path, int flags) t -= 2; break; case 2: - if ((flags & (PATH_DOTDOT | PATH_EXISTS)) == PATH_DOTDOT - && (t - 2) >= v) { - struct stat st; - - *(t - 2) = 0; - if (stat(phys, &st)) { - strcpy(path, s); - return 0; - } - *(t - 2) = '.'; - } if (t - 5 < r) { if (t - 4 == r) t = r + 1; @@ -113,7 +86,7 @@ char *pathcanon(char *path, int flags) r = path; if (t == r + 1) x = r; - v = s = t = x; + s = t = x; } else { *t = c; t = o; @@ -124,49 +97,8 @@ char *pathcanon(char *path, int flags) #endif break; default: - if ((flags & PATH_PHYSICAL) && loop < 32 && (t - 1) > path) { - char buf[PATH_MAX]; - - char c = *(t - 1); - *(t - 1) = '\0'; - size_t len = pathgetlink(phys, buf, sizeof(buf)); - *(t - 1) = c; - if (len != SIZE_MAX && len > 0) { - if ((t + len + 1) >= e) { /* make sure path fits in buf */ - strcpy(path, s); - return 0; - } - loop++; - strcpy(buf + len, s - (*s != 0)); - if (*buf == '/') - p = r = path; - v = s = t = p; - strcpy(p, buf); - } else if (len == SIZE_MAX && errno == ENOENT) { - if (flags & PATH_EXISTS) { - strcpy(path, s); - return 0; - } - flags &= ~(PATH_PHYSICAL | PATH_DOTDOT); - } - dots = 4; - } break; } - if (dots >= 4 && (flags & PATH_EXISTS) && (t - 1) >= v - && (t > path + 1 - || (t > path && *(t - 1) && *(t - 1) != '/'))) { - struct stat st; - - *(t - 1) = 0; - if (stat(phys, &st)) { - strcpy(path, s); - return 0; - } - v = t; - if (*s) - *(t - 1) = '/'; - } if (!*s) { if (t > path && !*(t - 1)) t--; @@ -180,7 +112,6 @@ char *pathcanon(char *path, int flags) return t; } dots = 0; - p = t; break; default: dots = 4; -- 2.40.0