diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-01-11 19:20:11 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2006-01-11 19:20:11 +0000 |
commit | 2a36edfe207e9d7f780b408b9b606e2fd8ce57cb (patch) | |
tree | 25cf7a071a6a11c2ede4d7af0045f4b610131791 /usr.bin/less | |
parent | fe0a60db74addc3ac3de8577889a329c8aaef296 (diff) |
Fix recovery of realloc failure, which causes a segv on files with
very lone lines, as reported by Steffen Wendzel. ok deraadt@
Diffstat (limited to 'usr.bin/less')
-rw-r--r-- | usr.bin/less/line.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/usr.bin/less/line.c b/usr.bin/less/line.c index bd82f504c20..3c6a906a92d 100644 --- a/usr.bin/less/line.c +++ b/usr.bin/less/line.c @@ -80,14 +80,18 @@ init_line() expand_linebuf() { int new_size = size_linebuf * 2; - char *new_buf = (char *) realloc(linebuf, new_size); - char *new_attr = (char *) realloc(attr, new_size); - if (new_buf == NULL || new_attr == NULL) - { - if (new_attr != NULL) - free(new_attr); - if (new_buf != NULL) - free(new_buf); + char *new_buf; + char *new_attr; + + new_buf = realloc(linebuf, new_size); + if (new_buf == NULL) + return 1; + new_attr = realloc(attr, new_size); + if (new_attr == NULL) { + /* realloc linebuf back to original size */ + linebuf = realloc(new_buf, size_linebuf); + if (linebuf == NULL) + err(1, NULL); return 1; } memset(new_buf + size_linebuf, 0, new_size - size_linebuf); |