summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/hist.c21
-rw-r--r--Src/subst.c4
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(&copy);
break;
case 'A':
- chrealpath(&copy);
+ chrealpath(&copy, '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':
{