Author: Raphael Geissert Bug-Debian: https://bugs.debian.org/731860 Description: Avoid directory traversal when extracting archives by skipping over leading slashes and any prefix containing ".." components. Forwarded: yes --- a/lib/decode.c +++ b/lib/decode.c @@ -22,6 +22,36 @@ #endif +char * +safer_name_suffix (char const *file_name) +{ + char const *p, *t; + p = t = file_name; + while (*p == '/') t = ++p; + while (*p) + { + while (p[0] == '.' && p[0] == p[1] && p[2] == '/') + { + p += 3; + t = p; + } + /* advance pointer past the next slash */ + while (*p && (p++)[0] != '/'); + } + + if (!*t) + { + t = "."; + } + + if (t != file_name) + { + /* TODO: warn somehow that the path was modified */ + } + return (char*)t; +} + + /* determine full path name */ char * th_get_pathname(TAR *t) @@ -29,17 +59,17 @@ th_get_pathname(TAR *t) static char filename[MAXPATHLEN]; if (t->th_buf.gnu_longname) - return t->th_buf.gnu_longname; + return safer_name_suffix(t->th_buf.gnu_longname); if (t->th_buf.prefix[0] != '\0') { snprintf(filename, sizeof(filename), "%.155s/%.100s", t->th_buf.prefix, t->th_buf.name); - return filename; + return safer_name_suffix(filename); } snprintf(filename, sizeof(filename), "%.100s", t->th_buf.name); - return filename; + return safer_name_suffix(filename); } --- a/lib/extract.c +++ b/lib/extract.c @@ -298,14 +298,14 @@ tar_extract_hardlink(TAR * t, char *real if (mkdirhier(dirname(filename)) == -1) return -1; libtar_hashptr_reset(&hp); - if (libtar_hash_getkey(t->h, &hp, th_get_linkname(t), + if (libtar_hash_getkey(t->h, &hp, safer_name_suffix(th_get_linkname(t)), (libtar_matchfunc_t)libtar_str_match) != 0) { lnp = (char *)libtar_hashptr_data(&hp); linktgt = &lnp[strlen(lnp) + 1]; } else - linktgt = th_get_linkname(t); + linktgt = safer_name_suffix(th_get_linkname(t)); #ifdef DEBUG printf(" ==> extracting: %s (link to %s)\n", filename, linktgt); @@ -343,9 +343,9 @@ tar_extract_symlink(TAR *t, char *realna #ifdef DEBUG printf(" ==> extracting: %s (symlink to %s)\n", - filename, th_get_linkname(t)); + filename, safer_name_suffix(th_get_linkname(t))); #endif - if (symlink(th_get_linkname(t), filename) == -1) + if (symlink(safer_name_suffix(th_get_linkname(t)), filename) == -1) { #ifdef DEBUG perror("symlink()"); --- a/lib/internal.h +++ b/lib/internal.h @@ -15,3 +15,4 @@ #include +char* safer_name_suffix(char const*); --- a/lib/output.c +++ b/lib/output.c @@ -123,9 +123,9 @@ th_print_long_ls(TAR *t) else printf(" link to "); if ((t->options & TAR_GNU) && t->th_buf.gnu_longlink != NULL) - printf("%s", t->th_buf.gnu_longlink); + printf("%s", safer_name_suffix(t->th_buf.gnu_longlink)); else - printf("%.100s", t->th_buf.linkname); + printf("%.100s", safer_name_suffix(t->th_buf.linkname)); } putchar('\n'); msg-avail'>...Following discussions in <https://issues.guix.gnu.org/43893>, keeping a copy of the updated package source is desirable when generating a release. * build-aux/update-guix-package.scm (version-controlled?): Remove variable. (call-with-temporary-git-worktree): Renamed from 'with-temporary-git-worktree'. Update doc. Do not change directory implicitly. Define as a procedure, not a syntax. (keep-source-in-store): New procedure. (main): Adjust to use with call-with-temporary-git-worktree. Add the sources to the store when GUIX_ALLOW_ME_TO_USE_PRIVATE_COMMIT is set. Exit gracefully when FIND-ORIGIN-REMOTE returns #f. (%savannah-guix-git-repo-push-url-regexp): Adjust match for a potential colon separator. * Makefile.am (GUIX_ALLOW_ME_TO_USE_PRIVATE_COMMIT): Adjust. * .dir-locals.el (scheme-mode): Remove entry for with-temporary-git-worktree. * doc/contributing.texi (Updating the Guix Package): Update doc. Co-authored-by: Ludovic Courtès <ludo@gnu.org> Maxim Cournoyer 2020-10-25maint: update-guix-package: Include the git.sv.gnu.org alias....* build-aux/update-guix-package.scm (%savannah-guix-git-repo-push-url): Rename to... (%savannah-guix-git-repo-push-url-regexp): ...this. Add the 'sv' alternative to 'savannah' and the (push) suffix in the URL regexp. (find-origin-remote): Adjust accordingly. Reported-by: Ludovic Courtès <ludo@gnu.org> Maxim Cournoyer 2020-10-19maint: update-guix-package: Prevent accidentally breaking guix pull....Fixes <https://issues.guix.gnu.org/43893>. This changes the 'update-guix-package' tool so that it: 1. Always uses a clean checkout to compute the hash of the updated 'guix' package. 2. Ensures the commit used in the updated 'guix' package definition has already been pushed upstream. * build-aux/update-guix-package.scm (%savannah-guix-git-repo-push-url): New variable. (with-input-pipe-to-string, with-temporary-git-worktree): New syntaxes. (find-origin-remote, git-add-worktree): New procedures. (commit-already-pushed?): New predicate. (main): Check the commit used has already been pushed upstream and compute the hash from a clean checkout. * doc/contributing.texi (Updating the Guix Package): Document it. * .dir-locals.el (scheme-mode): Fix indentation of with-temporary-git-worktree. Maxim Cournoyer