diff options
author | Wayne Davison <wayned@users.sourceforge.net> | 2001-10-26 23:47:10 +0000 |
---|---|---|
committer | Wayne Davison <wayned@users.sourceforge.net> | 2001-10-26 23:47:10 +0000 |
commit | c1b837b152d412fd62b673d4f038bcfc73839d13 (patch) | |
tree | aa2934dfa29c6349a35577db805c16c5ed1cd51b /Src | |
parent | c9e1fd9567071050e673552088265963fbca9930 (diff) | |
download | zsh-c1b837b152d412fd62b673d4f038bcfc73839d13.tar.gz zsh-c1b837b152d412fd62b673d4f038bcfc73839d13.tar.xz zsh-c1b837b152d412fd62b673d4f038bcfc73839d13.zip |
Improved readhistline() to reject binary data better. (16184)
Diffstat (limited to 'Src')
-rw-r--r-- | Src/hist.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/Src/hist.c b/Src/hist.c index 4dacdd337..dfd34c716 100644 --- a/Src/hist.c +++ b/Src/hist.c @@ -1766,31 +1766,34 @@ static struct { static int histfile_linect; -static int readhistline(int start, char **bufp, int *bufsiz, FILE *in) +static int +readhistline(int start, char **bufp, int *bufsiz, FILE *in) { char *buf = *bufp; if (fgets(buf + start, *bufsiz - start, in)) { - int l = strlen(buf); - - if (start >= l) + int len = start + strlen(buf + start); + if (len == start) return -1; - - if (l) { - if (buf[l - 1] != '\n' && !feof(in)) { + if (buf[len - 1] != '\n') { + if (!feof(in)) { + if (len < (*bufsiz) - 1) + return -1; *bufp = zrealloc(buf, 2 * (*bufsiz)); *bufsiz = 2 * (*bufsiz); - return readhistline(l, bufp, bufsiz, in); + return readhistline(len, bufp, bufsiz, in); } - buf[l - 1] = '\0'; - if (l > 1 && buf[l - 2] == '\\') { - buf[--l - 1] = '\n'; + } + else { + buf[len - 1] = '\0'; + if (len > 1 && buf[len - 2] == '\\') { + buf[--len - 1] = '\n'; if (!feof(in)) - return readhistline(l, bufp, bufsiz, in); + return readhistline(len, bufp, bufsiz, in); } } - return l; - } else - return 0; + return len; + } + return 0; } /**/ |