From 7f580397e2c739b43513e77bf53d93e41c0a2deb Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 30 Dec 2010 18:05:53 -0500 Subject: [PATCH] Trim leading slashes from iolog_file and trailing slashes from iolog_dir --- plugins/sudoers/iolog.c | 23 ----------------------- plugins/sudoers/iolog_path.c | 7 +++++++ 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/plugins/sudoers/iolog.c b/plugins/sudoers/iolog.c index 0c5d5f546..d05b8e11d 100644 --- a/plugins/sudoers/iolog.c +++ b/plugins/sudoers/iolog.c @@ -209,29 +209,6 @@ mkdir_iopath(const char *iolog_path, char *pathbuf, size_t pathsize) { int len; -#if 0 /* XXX - move this into sudoers when it concats dir + file */ - /* Trim extraneous slashes. */ - dirlen = strlen(iolog_dir); - while (dirlen > 1 && iolog_dir[dirlen - 1] == '/') - dirlen--; - while (*iolog_file == '/') - iolog_file++; - filelen = strlen(iolog_file); - while (filelen > 1 && iolog_file[filelen - 1] == '/') - filelen--; - - if (*iolog_dir != '/' || *iolog_file == '\0') - log_error(0, "invalid I/O log path: %s/%s", iolog_dir, iolog_file); - - len = snprintf(pathbuf, pathsize, "%.*s/%.*s", dirlen, iolog_dir, - filelen, iolog_file); - if (len <= 0 && len >= pathsize) { - errno = ENAMETOOLONG; - log_error(USE_ERRNO, "%.*s/%.*s", dirlen, iolog_dir, - filelen, iolog_file); - } -#endif - len = strlcpy(pathbuf, iolog_path, pathsize); if (len >= pathsize) { errno = ENAMETOOLONG; diff --git a/plugins/sudoers/iolog_path.c b/plugins/sudoers/iolog_path.c index 17fb8d500..c0eb5d87f 100644 --- a/plugins/sudoers/iolog_path.c +++ b/plugins/sudoers/iolog_path.c @@ -156,6 +156,10 @@ expand_iolog_path(const char *prefix, const char *dir, const char *file) dst = path = emalloc(psize); *path = '\0'; + /* Trim leading slashes from file component. */ + while (*file == '/') + file++; + if (prefix != NULL) { plen = strlcpy(path, prefix, psize); dst += plen; @@ -166,6 +170,9 @@ expand_iolog_path(const char *prefix, const char *dir, const char *file) src = dir; break; case 1: + /* Only add path separator if dir doesn't end in a slash. */ + if (dst > path && dst[-1] == '/') + continue; src = "/"; break; case 2: -- 2.40.0