summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorstefanf <stefanf@FreeBSD.org>2006-04-29 10:29:10 +0000
committerstefanf <stefanf@FreeBSD.org>2006-04-29 10:29:10 +0000
commit0217b84e8a5ba9e2a460b9d1a42d6bd063d2e788 (patch)
tree3ca737d0266af7e1638c25a6315acb0541c6c315 /bin
parent78ed66ae083c20c8fc784c109730c53a45725865 (diff)
downloadFreeBSD-src-0217b84e8a5ba9e2a460b9d1a42d6bd063d2e788.zip
FreeBSD-src-0217b84e8a5ba9e2a460b9d1a42d6bd063d2e788.tar.gz
Check the buffer size when copying the line returned by el_gets() into our
own buffer. Interactively typing in long lines (>1023 characters) previously overflowed the buffer. Unlike the NetBSD people I don't see the need to subtract 8 from BUFSIZ, so I just used BUFSIZ-1. Obtained from: NetBSD PR: 91110
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/input.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/bin/sh/input.c b/bin/sh/input.c
index f4bb703..81c1f0b 100644
--- a/bin/sh/input.c
+++ b/bin/sh/input.c
@@ -184,14 +184,23 @@ preadfd(void)
retry:
#ifndef NO_HISTORY
if (parsefile->fd == 0 && el) {
- const char *rl_cp;
+ static const char *rl_cp;
+ static int el_len;
- rl_cp = el_gets(el, &nr);
+ if (rl_cp == NULL)
+ rl_cp = el_gets(el, &el_len);
if (rl_cp == NULL)
nr = 0;
else {
- /* XXX - BUFSIZE should redesign so not necessary */
- (void) strcpy(parsenextc, rl_cp);
+ nr = el_len;
+ if (nr > BUFSIZ - 1)
+ nr = BUFSIZ - 1;
+ memcpy(parsenextc, rl_cp, nr);
+ if (nr != el_len) {
+ el_len -= nr;
+ rl_cp += nr;
+ } else
+ rl_cp = NULL;
}
} else
#endif
OpenPOWER on IntegriCloud