diff options
author | Daniel Shahaf <d.s@daniel.shahaf.name> | 2020-03-21 18:01:36 +0000 |
---|---|---|
committer | Daniel Shahaf <d.s@daniel.shahaf.name> | 2020-03-25 23:49:01 +0000 |
commit | 38b0e1ff7e1bfcb8c7c6dffc328e2b98297b1878 (patch) | |
tree | c4053e7e8408fc45ed6f3f4a130cf93f63a79600 | |
parent | de587b43ba10fc11159630fd63486e247ea8719c (diff) | |
download | zsh-38b0e1ff7e1bfcb8c7c6dffc328e2b98297b1878.tar.gz zsh-38b0e1ff7e1bfcb8c7c6dffc328e2b98297b1878.tar.xz zsh-38b0e1ff7e1bfcb8c7c6dffc328e2b98297b1878.zip |
45583/0002: chrealpath: Make symlink resolution optional.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | Src/hist.c | 21 | ||||
-rw-r--r-- | Src/subst.c | 4 |
3 files changed, 21 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog index 5f291fec0..d45fcc670 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2020-03-25 Daniel Shahaf <d.s@daniel.shahaf.name> + * 45583/0002: Src/hist.c, Src/subst.c: chrealpath: Make symlink + resolution optional. + * 45583/0001: Test/D02glob.ztst: Add tests for the segfault on resolving a symlink loop bug (workers/45282). diff --git a/Src/hist.c b/Src/hist.c index 5281e8718..db2cc4ad7 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -842,7 +842,7 @@ histsubchar(int c) break; case 'A': - if (!chrealpath(&sline)) { + if (!chrealpath(&sline, 'A')) { herrflush(); zerr("modifier failed: A"); return -1; @@ -1922,9 +1922,18 @@ chabspath(char **junkptr) return 1; } +/* + * Resolve symlinks in junkptr. + * + * If mode is 'A', resolve dot-dot before symlinks. Else, mode should be 'P'. + * Refer to the documentation of the :A and :P modifiers for details. + * + * Return 0 for error, non-zero for success. + */ + /**/ int -chrealpath(char **junkptr) +chrealpath(char **junkptr, char mode) { char *str; #ifdef HAVE_REALPATH @@ -1936,12 +1945,14 @@ chrealpath(char **junkptr) # endif #endif + DPUTS1(mode != 'A' && mode != 'P', "chrealpath: mode='%c' is invalid", mode); + if (!**junkptr) return 1; - /* Notice that this means ..'s are applied before symlinks are resolved! */ - if (!chabspath(junkptr)) - return 0; + if (mode == 'A') + if (!chabspath(junkptr)) + return 0; #ifndef HAVE_REALPATH return 1; diff --git a/Src/subst.c b/Src/subst.c index 79efc9ad2..7b3222d6e 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -4399,7 +4399,7 @@ modify(char **str, char **ptr, int inbrace) chabspath(©); break; case 'A': - chrealpath(©); + chrealpath(©, 'A'); break; case 'c': { @@ -4485,7 +4485,7 @@ modify(char **str, char **ptr, int inbrace) chabspath(str); break; case 'A': - chrealpath(str); + chrealpath(str, 'A'); break; case 'c': { |