summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/parser.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/bin/sh/parser.c b/bin/sh/parser.c
index f3cc98d..cc04a2a 100644
--- a/bin/sh/parser.c
+++ b/bin/sh/parser.c
@@ -1998,7 +1998,7 @@ getprompt(void *unused __unused)
/*
* Format prompt string.
*/
- for (i = 0; (i < 127) && (*fmt != '\0'); i++, fmt++)
+ for (i = 0; (i < PROMPTLEN - 1) && (*fmt != '\0'); i++, fmt++)
if (*fmt == '\\')
switch (*++fmt) {
@@ -2011,7 +2011,8 @@ getprompt(void *unused __unused)
case 'h':
case 'H':
ps[i] = '\0';
- gethostname(&ps[i], PROMPTLEN - i);
+ gethostname(&ps[i], PROMPTLEN - i - 1);
+ ps[PROMPTLEN - 1] = '\0';
/* Skip to end of hostname. */
trim = (*fmt == 'h') ? '.' : '\0';
while ((ps[i] != '\0') && (ps[i] != trim))
@@ -2061,8 +2062,9 @@ getprompt(void *unused __unused)
* Emit unrecognized formats verbatim.
*/
default:
- ps[i++] = '\\';
- ps[i] = *fmt;
+ ps[i] = '\\';
+ if (i < PROMPTLEN - 1)
+ ps[++i] = *fmt;
break;
}
else
OpenPOWER on IntegriCloud