X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libbb%2Funarchive.c;h=782efd0a4a2065ab3ec780287b452d773977c4bb;hp=4e3a2edc04463b75e88cf86ca3535f17c39f7059;hb=53a42ce9e6cd906013c8d478751f496f2b367e5f;hpb=046cea8149c35b8d0dca6246c284f1d3c004410d diff --git a/libbb/unarchive.c b/libbb/unarchive.c index 4e3a2ed..782efd0 100644 --- a/libbb/unarchive.c +++ b/libbb/unarchive.c @@ -38,6 +38,7 @@ static char *linkname = NULL; extern void seek_sub_file(FILE *src_stream, const int count); extern char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *file_entry, const int function, const char *prefix); +extern ssize_t seek_by_read(FILE* fd, size_t len); #ifdef L_archive_offset @@ -47,16 +48,31 @@ extern off_t archive_offset; #endif #ifdef L_seek_sub_file +#define SEEK_BUF 4096 +ssize_t seek_by_read(FILE* fd, size_t len) +{ + ssize_t cc, total = 0; + char buf[SEEK_BUF]; + + while (len) { + cc = fread(buf, sizeof(buf[0]), + len > SEEK_BUF ? SEEK_BUF : len, + fd); + + total += cc; + len -= cc; + + if(feof(fd) || ferror(fd)) + break; + } + return total; +} + void seek_sub_file(FILE *src_stream, const int count) { - int i; /* Try to fseek as faster */ archive_offset += count; - if (fseek(src_stream, count, SEEK_CUR) != 0 && errno == ESPIPE) { - for (i = 0; i < count; i++) { - fgetc(src_stream); - } - } + seek_by_read(src_stream, count); return; } #endif @@ -84,7 +100,6 @@ char *extract_archive(FILE *src_stream, FILE *out_stream, const file_header_t *f char *full_link_name = NULL; char *buffer = NULL; struct utimbuf t; - int res; /* prefix doesnt have to be a proper path it may prepend @@ -601,10 +616,16 @@ file_header_t *get_header_tar(FILE *tar_stream) linkname = NULL; } else #endif - if (tar.formated.prefix[0] == 0) { - tar_entry->name = strdup(tar.formated.name); - } else { - tar_entry->name = concat_path_file(tar.formated.prefix, tar.formated.name); + { + tar_entry->name = xstrndup(tar.formated.name, 100); + + if (tar.formated.prefix[0]) { + char *temp = tar_entry->name; + char *prefixTemp = xstrndup(tar.formated.prefix, 155); + tar_entry->name = concat_path_file(prefixTemp, temp); + free(temp); + free(prefixTemp); + } } // tar_entry->name = xstrdup(tar.formated.name); @@ -618,8 +639,7 @@ file_header_t *get_header_tar(FILE *tar_stream) tar_entry->gid = strtol(tar.formated.gid, NULL, 8); tar_entry->size = strtol(tar.formated.size, NULL, 8); tar_entry->mtime = strtol(tar.formated.mtime, NULL, 8); - tar_entry->link_name = strlen(tar.formated.linkname) ? - xstrdup(tar.formated.linkname) : NULL; + tar_entry->link_name = *tar.formated.linkname != '\0' ? xstrndup(tar.formated.linkname, 100) : NULL; tar_entry->device = (strtol(tar.formated.devmajor, NULL, 8) << 8) + strtol(tar.formated.devminor, NULL, 8); @@ -751,6 +771,10 @@ char *deb_extract(const char *package_filename, FILE *out_stream, if (strcmp(ared_file, ar_header->name) == 0) { /* open a stream of decompressed data */ uncompressed_stream = gz_open(deb_stream, &gunzip_pid); + if (uncompressed_stream == NULL) { + return(NULL); + } + archive_offset = 0; output_buffer = unarchive(uncompressed_stream, out_stream, get_header_tar, free_header_tar, extract_function, prefix, file_list); } @@ -771,6 +795,9 @@ char *deb_extract(const char *package_filename, FILE *out_stream, archive_offset = 0; fseek(deb_stream, 0, SEEK_SET); unzipped_opkg_stream = gz_open(deb_stream, &unzipped_opkg_pid); + if (unzipped_opkg_stream == NULL) { + return(NULL); + } /*fprintf(stderr, __FUNCTION__ ": processing opkg %s -- ared_file=%s\n", package_filename, ared_file);*/ /* walk through outer tar file to find ared_file */ @@ -781,6 +808,9 @@ char *deb_extract(const char *package_filename, FILE *out_stream, if (strcmp(ared_file, tar_header->name+name_offset) == 0) { /* open a stream of decompressed data */ uncompressed_stream = gz_open(unzipped_opkg_stream, &gunzip_pid); + if (uncompressed_stream == NULL) { + return(NULL); + } archive_offset = 0; /*fprintf(stderr, __FUNCTION__ ":%d: here -- found file\n", __LINE__);*/ output_buffer = unarchive(uncompressed_stream,