aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDon Lewis <truckman@FreeBSD.org>2016-05-23 01:01:23 +0000
committerDon Lewis <truckman@FreeBSD.org>2016-05-23 01:01:23 +0000
commit63a4675d89518c7d6c5dbae758d243d3776fa76c (patch)
treeee28858c22f7e3cd82d1b61ced08e18fb2efe8dc /bin
parent4c36e917b28093bb37f1a2efeee5182cf8230610 (diff)
Notes
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 f3cc98d43cb01..cc04a2ab97efc 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