From 76e93646210494c246dbc50373e8cab2ecaa7847 Mon Sep 17 00:00:00 2001 From: vangyzen Date: Wed, 11 May 2016 22:11:37 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.freebsd.org/base/stable/10@299487 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- bin/sh/parser.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/sh/parser.c b/bin/sh/parser.c index cb4f1ec0e..a5679b847 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') -- 2.45.0