summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorvangyzen <vangyzen@FreeBSD.org>2016-05-04 02:06:46 +0000
committervangyzen <vangyzen@FreeBSD.org>2016-05-04 02:06:46 +0000
commit0520b418110675ffa4da7672ea7bc35154730337 (patch)
tree8287a7c6693f4917393dd8323612dd64f9039fc0 /bin
parent732c37e6cb7a5394016baf0b4f40e0d646f23225 (diff)
downloadFreeBSD-src-0520b418110675ffa4da7672ea7bc35154730337.zip
FreeBSD-src-0520b418110675ffa4da7672ea7bc35154730337.tar.gz
sh: Handle empty hostname and $PWD when building prompt
If the hostname is empty and \h is used in $PS1, the remainder of the prompt following \h will be empty. Likewise for $PWD and \w. Fix it. Reviewed by: jilles MFC after: 1 week Sponsored by: Dell Inc. Differential Revision: https://reviews.freebsd.org/D6188
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/parser.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index 26c1362..f3cc98d 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -2014,8 +2014,9 @@ getprompt(void *unused __unused)
gethostname(&ps[i], PROMPTLEN - i);
/* Skip to end of hostname. */
trim = (*fmt == 'h') ? '.' : '\0';
- while ((ps[i+1] != '\0') && (ps[i+1] != trim))
+ while ((ps[i] != '\0') && (ps[i] != trim))
i++;
+ --i;
break;
/*
@@ -2027,7 +2028,7 @@ getprompt(void *unused __unused)
case 'W':
case 'w':
pwd = lookupvar("PWD");
- if (pwd == NULL)
+ if (pwd == NULL || *pwd == '\0')
pwd = "?";
if (*fmt == 'W' &&
*pwd == '/' && pwd[1] != '\0')
OpenPOWER on IntegriCloud