diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-02-15 07:49:01 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-02-15 15:21:15 -0800 |
commit | b76c5760919b33fe15d9350a23ccaebcc905397c (patch) | |
tree | 18ac1343300957ea4bb6bf68bd0bdd21c835fa66 | |
parent | a632605cdf74fe0ad72c3a234e0cbf748f25bcff (diff) | |
download | txr-b76c5760919b33fe15d9350a23ccaebcc905397c.tar.gz txr-b76c5760919b33fe15d9350a23ccaebcc905397c.tar.bz2 txr-b76c5760919b33fe15d9350a23ccaebcc905397c.zip |
listener: fix buffer overflow reading external file.
When an external file is edited, and is longer than the
listener's buffer allows, the buffer overflows, trashing the
other fields in the linenoise structure, and memory beyond.
* parser.c (lino_gets): Decrement nchar in the loop.
Also, eliminate useless return case.
-rw-r--r-- | parser.c | 7 |
1 files changed, 1 insertions, 6 deletions
@@ -1496,18 +1496,13 @@ static wchar_t *lino_gets(mem_t *stream_in, wchar_t *buf, size_t nchar) if (nchar == 0) return buf; - while (nchar > 1) { + while (nchar-- > 1) { val ch = get_char(stream); if (!ch) break; *ptr++ = c_num(ch); } - if (ptr == buf) { - *ptr++ = 0; - return 0; - } - *ptr++ = 0; return buf; } |