Adjust upstream patch for 4.2 release

This commit is contained in:
Bruno Wolff III 2012-11-25 17:25:38 -06:00
parent 038e2d1dea
commit af10d8978d
2 changed files with 92 additions and 103 deletions

View File

@ -80,8 +80,8 @@ Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
diff --git a/squashfs-tools/squashfs_fs.h b/squashfs-tools/squashfs_fs.h diff --git a/squashfs-tools/squashfs_fs.h b/squashfs-tools/squashfs_fs.h
index d1dc987..58d31f4 100644 index d1dc987..58d31f4 100644
--- a/squashfs-tools/squashfs_fs.h --- squashfs-tools/squashfs_fs.h
+++ b/squashfs-tools/squashfs_fs.h +++ squashfs-tools/squashfs_fs.h
@@ -39,6 +39,7 @@ @@ -39,6 +39,7 @@
#define SQUASHFS_FILE_LOG 17 #define SQUASHFS_FILE_LOG 17
@ -90,19 +90,17 @@ index d1dc987..58d31f4 100644
/* Max number of uids and gids */ /* Max number of uids and gids */
#define SQUASHFS_IDS 65536 #define SQUASHFS_IDS 65536
diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c --- squashfs-tools/unsquashfs.c.buffer 2012-11-25 17:07:52.237809893 -0600
index d9d1377..1afcbf9 100644 +++ squashfs-tools/unsquashfs.c 2012-11-25 17:15:24.155246275 -0600
--- a/squashfs-tools/unsquashfs.c @@ -31,6 +31,7 @@
+++ b/squashfs-tools/unsquashfs.c
@@ -34,6 +34,7 @@ #include <sys/sysinfo.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <limits.h> +#include <limits.h>
struct cache *fragment_cache, *data_cache; struct cache *fragment_cache, *data_cache;
struct queue *to_reader, *to_deflate, *to_writer, *from_writer; struct queue *to_reader, *to_deflate, *to_writer, *from_writer;
@@ -139,6 +140,24 @@ void sigalrm_handler() @@ -136,6 +137,24 @@
} }
@ -127,7 +125,7 @@ index d9d1377..1afcbf9 100644
struct queue *queue_init(int size) struct queue *queue_init(int size)
{ {
struct queue *queue = malloc(sizeof(struct queue)); struct queue *queue = malloc(sizeof(struct queue));
@@ -146,6 +165,10 @@ struct queue *queue_init(int size) @@ -143,6 +162,10 @@
if(queue == NULL) if(queue == NULL)
EXIT_UNSQUASH("Out of memory in queue_init\n"); EXIT_UNSQUASH("Out of memory in queue_init\n");
@ -138,26 +136,19 @@ index d9d1377..1afcbf9 100644
queue->data = malloc(sizeof(void *) * (size + 1)); queue->data = malloc(sizeof(void *) * (size + 1));
if(queue->data == NULL) if(queue->data == NULL)
EXIT_UNSQUASH("Out of memory in queue_init\n"); EXIT_UNSQUASH("Out of memory in queue_init\n");
@@ -2015,13 +2038,30 @@ void initialise_threads(int fragment_buffer_size, int data_buffer_size) @@ -1805,7 +1828,7 @@
* allocate to_reader, to_deflate and to_writer queues. Set based on {
* open file limit and cache size, unless open file limit is unlimited, int i;
* in which case set purely based on cache limits sigset_t sigmask, old_mask;
+ *
+ * In doing so, check that the user supplied values do not overflow
+ * a signed int
*/
if (max_files != -1) {
+ if(add_overflow(data_buffer_size, max_files) ||
+ add_overflow(data_buffer_size, max_files * 2))
+ EXIT_UNSQUASH("Data queue size is too large\n");
+
to_reader = queue_init(max_files + data_buffer_size);
to_deflate = queue_init(max_files + data_buffer_size);
to_writer = queue_init(max_files * 2 + data_buffer_size);
} else {
- int all_buffers_size = fragment_buffer_size + data_buffer_size; - int all_buffers_size = fragment_buffer_size + data_buffer_size;
+ int all_buffers_size; + int all_buffers_size;
+
sigemptyset(&sigmask);
sigaddset(&sigmask, SIGINT);
@@ -1841,6 +1864,15 @@
EXIT_UNSQUASH("Out of memory allocating thread descriptors\n");
deflator_thread = &thread[3];
+ if(add_overflow(fragment_buffer_size, data_buffer_size)) + if(add_overflow(fragment_buffer_size, data_buffer_size))
+ EXIT_UNSQUASH("Data and fragment queues combined are" + EXIT_UNSQUASH("Data and fragment queues combined are"
+ " too large\n"); + " too large\n");
@ -167,13 +158,13 @@ index d9d1377..1afcbf9 100644
+ if(add_overflow(all_buffers_size, all_buffers_size)) + if(add_overflow(all_buffers_size, all_buffers_size))
+ EXIT_UNSQUASH("Data and fragment queues combined are" + EXIT_UNSQUASH("Data and fragment queues combined are"
+ " too large\n"); + " too large\n");
to_reader = queue_init(all_buffers_size); to_reader = queue_init(all_buffers_size);
to_deflate = queue_init(all_buffers_size); to_deflate = queue_init(all_buffers_size);
@@ -2126,8 +2166,34 @@ void progress_bar(long long current, long long max, int columns) to_writer = queue_init(1000);
@@ -1940,6 +1972,31 @@
fflush(stdout);
} }
+int parse_number(char *arg, int *res) +int parse_number(char *arg, int *res)
+{ +{
+ char *b; + char *b;
@ -199,14 +190,10 @@ index d9d1377..1afcbf9 100644
+ return 1; + return 1;
+} +}
+ +
+
#define VERSION() \ #define VERSION() \
- printf("unsquashfs version 4.2-git (2012/11/21)\n");\ printf("unsquashfs version 4.2 (2011/02/28)\n");\
+ printf("unsquashfs version 4.2-git (2012/11/24)\n");\ @@ -2022,8 +2079,8 @@
printf("copyright (C) 2012 Phillip Lougher "\
"<phillip@squashfs.org.uk>\n\n");\
printf("This program is free software; you can redistribute it and/or"\
@@ -2207,8 +2273,8 @@ int main(int argc, char *argv[])
} else if(strcmp(argv[i], "-data-queue") == 0 || } else if(strcmp(argv[i], "-data-queue") == 0 ||
strcmp(argv[i], "-da") == 0) { strcmp(argv[i], "-da") == 0) {
if((++i == argc) || if((++i == argc) ||
@ -217,7 +204,7 @@ index d9d1377..1afcbf9 100644
ERROR("%s: -data-queue missing or invalid " ERROR("%s: -data-queue missing or invalid "
"queue size\n", argv[0]); "queue size\n", argv[0]);
exit(1); exit(1);
@@ -2221,8 +2287,8 @@ int main(int argc, char *argv[]) @@ -2036,8 +2093,8 @@
} else if(strcmp(argv[i], "-frag-queue") == 0 || } else if(strcmp(argv[i], "-frag-queue") == 0 ||
strcmp(argv[i], "-fr") == 0) { strcmp(argv[i], "-fr") == 0) {
if((++i == argc) || if((++i == argc) ||
@ -228,10 +215,13 @@ index d9d1377..1afcbf9 100644
ERROR("%s: -frag-queue missing or invalid " ERROR("%s: -frag-queue missing or invalid "
"queue size\n", argv[0]); "queue size\n", argv[0]);
exit(1); exit(1);
@@ -2347,11 +2413,39 @@ options: @@ -2161,8 +2218,41 @@
block_size = sBlk.s.block_size;
block_log = sBlk.s.block_log; block_log = sBlk.s.block_log;
/* - fragment_buffer_size <<= 20 - block_log;
- data_buffer_size <<= 20 - block_log;
+ /*
+ * Sanity check block size and block log. + * Sanity check block size and block log.
+ * + *
+ * Check they're within correct limits + * Check they're within correct limits
@ -249,15 +239,12 @@ index d9d1377..1afcbf9 100644
+ " File system is corrupt.\n"); + " File system is corrupt.\n");
+ +
+ /* + /*
* convert from queue size in Mbytes to queue size in + * convert from queue size in Mbytes to queue size in
- * blocks
+ * blocks. + * blocks.
+ * + *
+ * In doing so, check that the user supplied values do not + * In doing so, check that the user supplied values do not
+ * overflow a signed int + * overflow a signed int
*/ + */
- fragment_buffer_size <<= 20 - block_log;
- data_buffer_size <<= 20 - block_log;
+ if(shift_overflow(fragment_buffer_size, 20 - block_log)) + if(shift_overflow(fragment_buffer_size, 20 - block_log))
+ EXIT_UNSQUASH("Fragment queue size is too large\n"); + EXIT_UNSQUASH("Fragment queue size is too large\n");
+ else + else
@ -267,6 +254,7 @@ index d9d1377..1afcbf9 100644
+ EXIT_UNSQUASH("Data queue size is too large\n"); + EXIT_UNSQUASH("Data queue size is too large\n");
+ else + else
+ data_buffer_size <<= 20 - block_log; + data_buffer_size <<= 20 - block_log;
+
+ +
initialise_threads(fragment_buffer_size, data_buffer_size); initialise_threads(fragment_buffer_size, data_buffer_size);

View File

@ -15,6 +15,7 @@ BuildRequires: libattr-devel
# date change that doesn't apply cleanly) # date change that doesn't apply cleanly)
Patch0: path-issue.patch Patch0: path-issue.patch
# Upstream commit 8515b3d420f502c5c0236b86e2d6d7e3b23c190e # Upstream commit 8515b3d420f502c5c0236b86e2d6d7e3b23c190e
# Patch needed to be adjusted to fit with the 4.2 release
Patch1: buffer-issue.patch Patch1: buffer-issue.patch
%description %description
@ -24,7 +25,7 @@ contains the utilities for manipulating squashfs filesystems.
%prep %prep
%setup -q -n squashfs4.2 %setup -q -n squashfs4.2
%patch0 -p1 -b .pathname %patch0 -p1 -b .pathname
%patch1 -p1 -b .buffer %patch1 -p0 -b .buffer
%build %build
pushd squashfs-tools pushd squashfs-tools