diff options
author | vangyzen <vangyzen@FreeBSD.org> | 2016-05-11 22:11:37 +0000 |
---|---|---|
committer | vangyzen <vangyzen@FreeBSD.org> | 2016-05-11 22:11:37 +0000 |
commit | 0c387e6a51840fe615c91e95a552ca9025d62d3b (patch) | |
tree | c47f38aeffb83b793e106772444235c24c266464 | |
parent | 4dc4a1749542ffb3325a4c24d3b96ce61d3e1531 (diff) | |
download | FreeBSD-src-0c387e6a51840fe615c91e95a552ca9025d62d3b.zip FreeBSD-src-0c387e6a51840fe615c91e95a552ca9025d62d3b.tar.gz |
MFC r299035: 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.
-rw-r--r-- | bin/sh/parser.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c index cb4f1ec0..a5679b8 100644 --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -1990,8 +1990,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; /* @@ -2003,7 +2004,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') |