Skip to content

Commit

Permalink
fix strdup() on possibly unterminated string
Browse files Browse the repository at this point in the history
Otherwise, a buffer read overflow may happen at
file.c line 236
  • Loading branch information
pauldreik committed Oct 31, 2019
1 parent 75b2146 commit 7109b9e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,14 @@ attr_read (FILE* in)
attr->type = (type_and_name >> 16);
attr->name = ((type_and_name << 16) >> 16);
attr->len = geti32(in);
attr->buf = CHECKED_XCALLOC (unsigned char, attr->len);
/* Allocate an extra byte for the null terminator. */
attr->buf = CHECKED_XCALLOC (unsigned char, attr->len + 1);

(void)getbuf(in, attr->buf, attr->len);
/* Always null terminate, in case the input lacks it,
this avoids strdup() being invoked on possibly non-terminated
input later (file.c, file_add_attr()). */
attr->buf[attr->len]='\0';

checksum = geti16(in);
if (!check_checksum(attr, checksum))
Expand Down

0 comments on commit 7109b9e

Please sign in to comment.