/* Parse the size of the name, adjust the file size. */
number = ar_atol10(h + AR_name_offset + 3, AR_name_size - 3);
- if ((off_t)number > ar->entry_bytes_remaining) {
+ bsd_name_length = (size_t)number;
+ /* Guard against the filename + trailing NUL
+ * overflowing a size_t and against the filename size
+ * being larger than the entire entry. */
+ if (number > (uint64_t)(bsd_name_length + 1)
+ || (uint64_t)bsd_name_length > ar->entry_bytes_remaining) {
archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
"Bad input file size");
return (ARCHIVE_FATAL);
}
- bsd_name_length = (size_t)number;
ar->entry_bytes_remaining -= bsd_name_length;
/* Adjust file size reported to client. */
archive_entry_set_size(entry, ar->entry_bytes_remaining);
struct file_info **new_pending_files;
int new_size = iso9660->pending_files_allocated * 2;
+ /* Overflow might keep us from growing the list. */
+ if (new_size <= iso9660->pending_files_allocated)
+ __archive_errx(1, "Out of memory");
if (new_size < 1024)
new_size = 1024;
new_pending_files = (struct file_info **)malloc(new_size * sizeof(new_pending_files[0]));
fprintf(stderr, " (y/N)? ");
fflush(stderr);
- l = read(2, buff, sizeof(buff));
+ l = read(2, buff, sizeof(buff) - 1);
if (l <= 0)
return (0);
buff[l] = 0;
{
FILE *f;
char *buff, *buff_end, *line_start, *line_end, *p;
- size_t buff_length, bytes_read, bytes_wanted;
+ size_t buff_length, new_buff_length, bytes_read, bytes_wanted;
int separator;
int ret;
line_start = buff;
} else {
/* Line is too big; enlarge the buffer. */
- p = realloc(buff, buff_length *= 2);
+ new_buff_length = buff_length * 2;
+ if (new_buff_length <= buff_length)
+ bsdtar_errc(bsdtar, 1, ENOMEM,
+ "Line too long in %s", pathname);
+ buff_length = new_buff_length;
+ p = realloc(buff, buff_length);
if (p == NULL)
bsdtar_errc(bsdtar, 1, ENOMEM,
"Line too long in %s", pathname);