1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-06-11 01:36:03 +02:00

Improved readhistline() to reject binary data better. (16184)

This commit is contained in:
Wayne Davison 2001-10-26 23:47:10 +00:00
parent c9e1fd9567
commit c1b837b152

View File

@ -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);
}
buf[l - 1] = '\0';
if (l > 1 && buf[l - 2] == '\\') {
buf[--l - 1] = '\n';
if (!feof(in))
return readhistline(l, bufp, bufsiz, in);
return readhistline(len, bufp, bufsiz, in);
}
}
return l;
} else
return 0;
else {
buf[len - 1] = '\0';
if (len > 1 && buf[len - 2] == '\\') {
buf[--len - 1] = '\n';
if (!feof(in))
return readhistline(len, bufp, bufsiz, in);
}
}
return len;
}
return 0;
}
/**/