diff --git a/qubes-rpc/tar2qfile.c b/qubes-rpc/tar2qfile.c index e647a317..254a1d82 100644 --- a/qubes-rpc/tar2qfile.c +++ b/qubes-rpc/tar2qfile.c @@ -37,6 +37,7 @@ */ #define _GNU_SOURCE /* For O_NOFOLLOW. */ +#include #include #include #include @@ -750,7 +751,10 @@ ustar_rd (int fd, struct file_header * untrusted_hdr, char *buf, struct stat * s #ifdef DEBUG fprintf(stderr,"Inserting %s into register\n",path); #endif - dirs_headers_sent = realloc(dirs_headers_sent, sizeof (char*) * (++n_dirs)); + size_t new_alloc_size; + if (n_dirs >= INT_MAX || __builtin_mul_overflow(sizeof(char *), ++n_dirs, &new_alloc_size)) + gui_fatal("Too many directories already sent"); + dirs_headers_sent = realloc(dirs_headers_sent, new_alloc_size); if (dirs_headers_sent == NULL) return MEMORY_ALLOC_FAILED; dirs_headers_sent[n_dirs-1] = malloc(sizeof (char) * (strlen(path)+1));