diff options
author | Alexander Kanavin <alex.kanavin@gmail.com> | 2022-04-07 19:00:16 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-04-19 14:14:11 +0100 |
commit | abff42ff318fd806d7607ed40da5bc0c89793d76 (patch) | |
tree | 4389b000ee4bf74027ebc1cdb3f8896aeaa4c2da /meta/recipes-devtools/squashfs-tools/squashfs-tools | |
parent | 15df00f0f0e3c15560b3f0774227817deade81f9 (diff) | |
download | poky-abff42ff318fd806d7607ed40da5bc0c89793d76.tar.gz |
squashfs-tools: update 4.5 -> 4.5.1
Drop backports.
Correctly set source and installation directories.
(From OE-Core rev: feaa1ed77c31a3c7dd8abe17d8d0e6f94157eb61)
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools/squashfs-tools/squashfs-tools')
5 files changed, 0 insertions, 932 deletions
diff --git a/meta/recipes-devtools/squashfs-tools/squashfs-tools/0001-Avoid-use-of-INSTALL_DIR-for-symlink-targets.patch b/meta/recipes-devtools/squashfs-tools/squashfs-tools/0001-Avoid-use-of-INSTALL_DIR-for-symlink-targets.patch deleted file mode 100644 index b505f05735..0000000000 --- a/meta/recipes-devtools/squashfs-tools/squashfs-tools/0001-Avoid-use-of-INSTALL_DIR-for-symlink-targets.patch +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | From c9e263a7add76df1ed92e879d964264067c0f6e8 Mon Sep 17 00:00:00 2001 | ||
2 | From: Patrick McCarty <patrick.mccarty@intel.com> | ||
3 | Date: Mon, 26 Jul 2021 11:38:43 -0700 | ||
4 | Subject: [PATCH] Avoid use of INSTALL_DIR for symlink targets | ||
5 | |||
6 | In case INSTALL_DIR is overridden with a staged install location, using | ||
7 | INSTALL_DIR for the symlink target path prefix will yield an incorrect location | ||
8 | for the final installation. | ||
9 | |||
10 | Because the symlink itself is already installed to INSTALL_DIR, simply removing | ||
11 | the INSTALL_DIR prefix suffices as a fix. | ||
12 | |||
13 | Note that using $DESTDIR/$INSTALL_DIR where appropriate can avoid this type of | ||
14 | issue, but that can be considered a future enhancement. | ||
15 | |||
16 | Upstream-Status: Backport | ||
17 | Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com> | ||
18 | Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com> | ||
19 | --- | ||
20 | squashfs-tools/Makefile | 4 ++-- | ||
21 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
22 | |||
23 | diff --git a/squashfs-tools/Makefile b/squashfs-tools/Makefile | ||
24 | index 5795d0d..998c5fd 100755 | ||
25 | --- a/Makefile | ||
26 | +++ b/Makefile | ||
27 | @@ -406,5 +406,5 @@ install: mksquashfs unsquashfs | ||
28 | mkdir -p $(INSTALL_DIR) | ||
29 | cp mksquashfs $(INSTALL_DIR) | ||
30 | cp unsquashfs $(INSTALL_DIR) | ||
31 | - ln -fs $(INSTALL_DIR)/unsquashfs $(INSTALL_DIR)/sqfscat | ||
32 | - ln -fs $(INSTALL_DIR)/mksquashfs $(INSTALL_DIR)/sqfstar | ||
33 | + ln -fs unsquashfs $(INSTALL_DIR)/sqfscat | ||
34 | + ln -fs mksquashfs $(INSTALL_DIR)/sqfstar | ||
diff --git a/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072-requisite-1.patch b/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072-requisite-1.patch deleted file mode 100644 index d01b5c6871..0000000000 --- a/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072-requisite-1.patch +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
1 | The commit is required by the fix for CVE-2021-41072. | ||
2 | |||
3 | Upstream-Status: Backport [https://github.com/plougher/squashfs-tools/commit/80b8441] | ||
4 | |||
5 | Signed-off-by: Kai Kang <kai.kang@windriver.com> | ||
6 | |||
7 | From 80b8441a37fcf8bf07dacf24d9d6c6459a0f6e36 Mon Sep 17 00:00:00 2001 | ||
8 | From: Phillip Lougher <phillip@squashfs.org.uk> | ||
9 | Date: Sun, 12 Sep 2021 19:58:19 +0100 | ||
10 | Subject: [PATCH] unsquashfs: use squashfs_closedir() to delete directory | ||
11 | |||
12 | Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk> | ||
13 | --- | ||
14 | squashfs-tools/unsquash-1.c | 3 +-- | ||
15 | squashfs-tools/unsquash-1234.c | 11 +++++++++-- | ||
16 | squashfs-tools/unsquash-2.c | 3 +-- | ||
17 | squashfs-tools/unsquash-3.c | 3 +-- | ||
18 | squashfs-tools/unsquash-4.c | 3 +-- | ||
19 | squashfs-tools/unsquashfs.c | 7 ------- | ||
20 | squashfs-tools/unsquashfs.h | 1 + | ||
21 | 7 files changed, 14 insertions(+), 17 deletions(-) | ||
22 | |||
23 | diff --git a/squashfs-tools/unsquash-1.c b/squashfs-tools/unsquash-1.c | ||
24 | index acba821..7598499 100644 | ||
25 | --- a/squashfs-tools/unsquash-1.c | ||
26 | +++ b/squashfs-tools/unsquash-1.c | ||
27 | @@ -373,8 +373,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
28 | return dir; | ||
29 | |||
30 | corrupted: | ||
31 | - free(dir->dirs); | ||
32 | - free(dir); | ||
33 | + squashfs_closedir(dir); | ||
34 | return NULL; | ||
35 | } | ||
36 | |||
37 | diff --git a/squashfs-tools/unsquash-1234.c b/squashfs-tools/unsquash-1234.c | ||
38 | index c2d4f42..0c8dfbb 100644 | ||
39 | --- a/squashfs-tools/unsquash-1234.c | ||
40 | +++ b/squashfs-tools/unsquash-1234.c | ||
41 | @@ -25,8 +25,8 @@ | ||
42 | * unsquash-4. | ||
43 | */ | ||
44 | |||
45 | -#define TRUE 1 | ||
46 | -#define FALSE 0 | ||
47 | +#include "unsquashfs.h" | ||
48 | + | ||
49 | /* | ||
50 | * Check name for validity, name should not | ||
51 | * - be ".", "./", or | ||
52 | @@ -56,3 +56,10 @@ int check_name(char *name, int size) | ||
53 | |||
54 | return TRUE; | ||
55 | } | ||
56 | + | ||
57 | + | ||
58 | +void squashfs_closedir(struct dir *dir) | ||
59 | +{ | ||
60 | + free(dir->dirs); | ||
61 | + free(dir); | ||
62 | +} | ||
63 | diff --git a/squashfs-tools/unsquash-2.c b/squashfs-tools/unsquash-2.c | ||
64 | index 0746b3d..86f62ba 100644 | ||
65 | --- a/squashfs-tools/unsquash-2.c | ||
66 | +++ b/squashfs-tools/unsquash-2.c | ||
67 | @@ -465,8 +465,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
68 | return dir; | ||
69 | |||
70 | corrupted: | ||
71 | - free(dir->dirs); | ||
72 | - free(dir); | ||
73 | + squashfs_closedir(dir); | ||
74 | return NULL; | ||
75 | } | ||
76 | |||
77 | diff --git a/squashfs-tools/unsquash-3.c b/squashfs-tools/unsquash-3.c | ||
78 | index 094caaa..c04aa9e 100644 | ||
79 | --- a/squashfs-tools/unsquash-3.c | ||
80 | +++ b/squashfs-tools/unsquash-3.c | ||
81 | @@ -499,8 +499,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
82 | return dir; | ||
83 | |||
84 | corrupted: | ||
85 | - free(dir->dirs); | ||
86 | - free(dir); | ||
87 | + squashfs_closedir(dir); | ||
88 | return NULL; | ||
89 | } | ||
90 | |||
91 | diff --git a/squashfs-tools/unsquash-4.c b/squashfs-tools/unsquash-4.c | ||
92 | index 3a1b9e1..ff62dcc 100644 | ||
93 | --- a/squashfs-tools/unsquash-4.c | ||
94 | +++ b/squashfs-tools/unsquash-4.c | ||
95 | @@ -436,8 +436,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
96 | return dir; | ||
97 | |||
98 | corrupted: | ||
99 | - free(dir->dirs); | ||
100 | - free(dir); | ||
101 | + squashfs_closedir(dir); | ||
102 | return NULL; | ||
103 | } | ||
104 | |||
105 | diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c | ||
106 | index 7b590bd..04be53c 100644 | ||
107 | --- a/squashfs-tools/unsquashfs.c | ||
108 | +++ b/squashfs-tools/unsquashfs.c | ||
109 | @@ -1350,13 +1350,6 @@ unsigned int *offset, unsigned int *type) | ||
110 | } | ||
111 | |||
112 | |||
113 | -void squashfs_closedir(struct dir *dir) | ||
114 | -{ | ||
115 | - free(dir->dirs); | ||
116 | - free(dir); | ||
117 | -} | ||
118 | - | ||
119 | - | ||
120 | char *get_component(char *target, char **targname) | ||
121 | { | ||
122 | char *start; | ||
123 | diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h | ||
124 | index 2e9201c..5ecb2ab 100644 | ||
125 | --- a/squashfs-tools/unsquashfs.h | ||
126 | +++ b/squashfs-tools/unsquashfs.h | ||
127 | @@ -291,4 +291,5 @@ extern long long *alloc_index_table(int); | ||
128 | |||
129 | /* unsquash-1234.c */ | ||
130 | extern int check_name(char *, int); | ||
131 | +extern void squashfs_closedir(struct dir *); | ||
132 | #endif | ||
133 | -- | ||
134 | 2.17.1 | ||
135 | |||
diff --git a/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072-requisite-2.patch b/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072-requisite-2.patch deleted file mode 100644 index 6b230b35c6..0000000000 --- a/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072-requisite-2.patch +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | The commit is required by the fix for CVE-2021-41072. | ||
2 | |||
3 | Upstream-Status: Backport [https://github.com/plougher/squashfs-tools/commit/1993a4e] | ||
4 | |||
5 | Signed-off-by: Kai Kang <kai.kang@windriver.com> | ||
6 | |||
7 | From 1993a4e7aeda04962bf26e84c15fba8b58837e10 Mon Sep 17 00:00:00 2001 | ||
8 | From: Phillip Lougher <phillip@squashfs.org.uk> | ||
9 | Date: Sun, 12 Sep 2021 20:09:13 +0100 | ||
10 | Subject: [PATCH] unsquashfs: dynamically allocate name | ||
11 | |||
12 | Dynamically allocate name rather than store it | ||
13 | directly in structure. | ||
14 | |||
15 | Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk> | ||
16 | --- | ||
17 | squashfs-tools/unsquash-1.c | 2 +- | ||
18 | squashfs-tools/unsquash-1234.c | 5 +++++ | ||
19 | squashfs-tools/unsquash-2.c | 2 +- | ||
20 | squashfs-tools/unsquash-3.c | 2 +- | ||
21 | squashfs-tools/unsquash-4.c | 2 +- | ||
22 | squashfs-tools/unsquashfs.h | 2 +- | ||
23 | 6 files changed, 10 insertions(+), 5 deletions(-) | ||
24 | |||
25 | diff --git a/squashfs-tools/unsquash-1.c b/squashfs-tools/unsquash-1.c | ||
26 | index 7598499..d0121c6 100644 | ||
27 | --- a/squashfs-tools/unsquash-1.c | ||
28 | +++ b/squashfs-tools/unsquash-1.c | ||
29 | @@ -360,7 +360,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
30 | dir->dirs = new_dir; | ||
31 | } | ||
32 | |||
33 | - strcpy(dir->dirs[dir->dir_count].name, dire->name); | ||
34 | + dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
35 | dir->dirs[dir->dir_count].start_block = | ||
36 | dirh.start_block; | ||
37 | dir->dirs[dir->dir_count].offset = dire->offset; | ||
38 | diff --git a/squashfs-tools/unsquash-1234.c b/squashfs-tools/unsquash-1234.c | ||
39 | index 0c8dfbb..ac46d9d 100644 | ||
40 | --- a/squashfs-tools/unsquash-1234.c | ||
41 | +++ b/squashfs-tools/unsquash-1234.c | ||
42 | @@ -60,6 +60,11 @@ int check_name(char *name, int size) | ||
43 | |||
44 | void squashfs_closedir(struct dir *dir) | ||
45 | { | ||
46 | + int i; | ||
47 | + | ||
48 | + for(i = 0; i < dir->dir_count; i++) | ||
49 | + free(dir->dirs[i].name); | ||
50 | + | ||
51 | free(dir->dirs); | ||
52 | free(dir); | ||
53 | } | ||
54 | diff --git a/squashfs-tools/unsquash-2.c b/squashfs-tools/unsquash-2.c | ||
55 | index 86f62ba..e847980 100644 | ||
56 | --- a/squashfs-tools/unsquash-2.c | ||
57 | +++ b/squashfs-tools/unsquash-2.c | ||
58 | @@ -452,7 +452,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
59 | dir->dirs = new_dir; | ||
60 | } | ||
61 | |||
62 | - strcpy(dir->dirs[dir->dir_count].name, dire->name); | ||
63 | + dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
64 | dir->dirs[dir->dir_count].start_block = | ||
65 | dirh.start_block; | ||
66 | dir->dirs[dir->dir_count].offset = dire->offset; | ||
67 | diff --git a/squashfs-tools/unsquash-3.c b/squashfs-tools/unsquash-3.c | ||
68 | index c04aa9e..8223f27 100644 | ||
69 | --- a/squashfs-tools/unsquash-3.c | ||
70 | +++ b/squashfs-tools/unsquash-3.c | ||
71 | @@ -486,7 +486,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
72 | dir->dirs = new_dir; | ||
73 | } | ||
74 | |||
75 | - strcpy(dir->dirs[dir->dir_count].name, dire->name); | ||
76 | + dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
77 | dir->dirs[dir->dir_count].start_block = | ||
78 | dirh.start_block; | ||
79 | dir->dirs[dir->dir_count].offset = dire->offset; | ||
80 | diff --git a/squashfs-tools/unsquash-4.c b/squashfs-tools/unsquash-4.c | ||
81 | index ff62dcc..1e199a7 100644 | ||
82 | --- a/squashfs-tools/unsquash-4.c | ||
83 | +++ b/squashfs-tools/unsquash-4.c | ||
84 | @@ -423,7 +423,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
85 | dir->dirs = new_dir; | ||
86 | } | ||
87 | |||
88 | - strcpy(dir->dirs[dir->dir_count].name, dire->name); | ||
89 | + dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
90 | dir->dirs[dir->dir_count].start_block = | ||
91 | dirh.start_block; | ||
92 | dir->dirs[dir->dir_count].offset = dire->offset; | ||
93 | diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h | ||
94 | index 5ecb2ab..583fbe4 100644 | ||
95 | --- a/squashfs-tools/unsquashfs.h | ||
96 | +++ b/squashfs-tools/unsquashfs.h | ||
97 | @@ -164,7 +164,7 @@ struct queue { | ||
98 | #define DIR_ENT_SIZE 16 | ||
99 | |||
100 | struct dir_ent { | ||
101 | - char name[SQUASHFS_NAME_LEN + 1]; | ||
102 | + char *name; | ||
103 | unsigned int start_block; | ||
104 | unsigned int offset; | ||
105 | unsigned int type; | ||
106 | -- | ||
107 | 2.17.1 | ||
108 | |||
diff --git a/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072-requisite-3.patch b/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072-requisite-3.patch deleted file mode 100644 index 5d5df6f15b..0000000000 --- a/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072-requisite-3.patch +++ /dev/null | |||
@@ -1,326 +0,0 @@ | |||
1 | The commit is required by the fix for CVE-2021-41072. | ||
2 | |||
3 | Upstream-Status: Backport [https://github.com/plougher/squashfs-tools/commit/9938154] | ||
4 | |||
5 | Signed-off-by: Kai Kang <kai.kang@windriver.com> | ||
6 | |||
7 | From 9938154174756ee48a94ea0b076397a2944b028d Mon Sep 17 00:00:00 2001 | ||
8 | From: Phillip Lougher <phillip@squashfs.org.uk> | ||
9 | Date: Sun, 12 Sep 2021 22:58:11 +0100 | ||
10 | Subject: [PATCH] unsquashfs: use linked list to store directory names | ||
11 | |||
12 | This should bring higher performance, and it allows sorting | ||
13 | if necessary (1.x and 2.0 filesystems). | ||
14 | |||
15 | Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk> | ||
16 | --- | ||
17 | squashfs-tools/unsquash-1.c | 30 +++++++++++++++--------------- | ||
18 | squashfs-tools/unsquash-1234.c | 12 ++++++++---- | ||
19 | squashfs-tools/unsquash-2.c | 29 +++++++++++++++-------------- | ||
20 | squashfs-tools/unsquash-3.c | 29 +++++++++++++++-------------- | ||
21 | squashfs-tools/unsquash-4.c | 29 +++++++++++++++-------------- | ||
22 | squashfs-tools/unsquashfs.c | 16 ++++++++++------ | ||
23 | squashfs-tools/unsquashfs.h | 3 ++- | ||
24 | 7 files changed, 80 insertions(+), 68 deletions(-) | ||
25 | |||
26 | diff --git a/squashfs-tools/unsquash-1.c b/squashfs-tools/unsquash-1.c | ||
27 | index d0121c6..b604434 100644 | ||
28 | --- a/squashfs-tools/unsquash-1.c | ||
29 | +++ b/squashfs-tools/unsquash-1.c | ||
30 | @@ -254,7 +254,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
31 | long long start; | ||
32 | int bytes = 0; | ||
33 | int dir_count, size, res; | ||
34 | - struct dir_ent *new_dir; | ||
35 | + struct dir_ent *ent, *cur_ent = NULL; | ||
36 | struct dir *dir; | ||
37 | |||
38 | TRACE("squashfs_opendir: inode start block %d, offset %d\n", | ||
39 | @@ -267,7 +267,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
40 | MEM_ERROR(); | ||
41 | |||
42 | dir->dir_count = 0; | ||
43 | - dir->cur_entry = 0; | ||
44 | + dir->cur_entry = NULL; | ||
45 | dir->mode = (*i)->mode; | ||
46 | dir->uid = (*i)->uid; | ||
47 | dir->guid = (*i)->gid; | ||
48 | @@ -351,20 +351,20 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
49 | "%d:%d, type %d\n", dire->name, | ||
50 | dirh.start_block, dire->offset, dire->type); | ||
51 | |||
52 | - if((dir->dir_count % DIR_ENT_SIZE) == 0) { | ||
53 | - new_dir = realloc(dir->dirs, (dir->dir_count + | ||
54 | - DIR_ENT_SIZE) * sizeof(struct dir_ent)); | ||
55 | - if(new_dir == NULL) | ||
56 | - MEM_ERROR(); | ||
57 | - | ||
58 | - dir->dirs = new_dir; | ||
59 | - } | ||
60 | + ent = malloc(sizeof(struct dir_ent)); | ||
61 | + if(ent == NULL) | ||
62 | + MEM_ERROR(); | ||
63 | |||
64 | - dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
65 | - dir->dirs[dir->dir_count].start_block = | ||
66 | - dirh.start_block; | ||
67 | - dir->dirs[dir->dir_count].offset = dire->offset; | ||
68 | - dir->dirs[dir->dir_count].type = dire->type; | ||
69 | + ent->name = strdup(dire->name); | ||
70 | + ent->start_block = dirh.start_block; | ||
71 | + ent->offset = dire->offset; | ||
72 | + ent->type = dire->type; | ||
73 | + ent->next = NULL; | ||
74 | + if(cur_ent == NULL) | ||
75 | + dir->dirs = ent; | ||
76 | + else | ||
77 | + cur_ent->next = ent; | ||
78 | + cur_ent = ent; | ||
79 | dir->dir_count ++; | ||
80 | bytes += dire->size + 1; | ||
81 | } | ||
82 | diff --git a/squashfs-tools/unsquash-1234.c b/squashfs-tools/unsquash-1234.c | ||
83 | index ac46d9d..e389f8d 100644 | ||
84 | --- a/squashfs-tools/unsquash-1234.c | ||
85 | +++ b/squashfs-tools/unsquash-1234.c | ||
86 | @@ -60,11 +60,15 @@ int check_name(char *name, int size) | ||
87 | |||
88 | void squashfs_closedir(struct dir *dir) | ||
89 | { | ||
90 | - int i; | ||
91 | + struct dir_ent *ent = dir->dirs; | ||
92 | |||
93 | - for(i = 0; i < dir->dir_count; i++) | ||
94 | - free(dir->dirs[i].name); | ||
95 | + while(ent) { | ||
96 | + struct dir_ent *tmp = ent; | ||
97 | + | ||
98 | + ent = ent->next; | ||
99 | + free(tmp->name); | ||
100 | + free(tmp); | ||
101 | + } | ||
102 | |||
103 | - free(dir->dirs); | ||
104 | free(dir); | ||
105 | } | ||
106 | diff --git a/squashfs-tools/unsquash-2.c b/squashfs-tools/unsquash-2.c | ||
107 | index e847980..956f96f 100644 | ||
108 | --- a/squashfs-tools/unsquash-2.c | ||
109 | +++ b/squashfs-tools/unsquash-2.c | ||
110 | @@ -347,7 +347,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
111 | long long start; | ||
112 | int bytes = 0; | ||
113 | int dir_count, size, res; | ||
114 | - struct dir_ent *new_dir; | ||
115 | + struct dir_ent *ent, *cur_ent = NULL; | ||
116 | struct dir *dir; | ||
117 | |||
118 | TRACE("squashfs_opendir: inode start block %d, offset %d\n", | ||
119 | @@ -360,7 +360,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
120 | MEM_ERROR(); | ||
121 | |||
122 | dir->dir_count = 0; | ||
123 | - dir->cur_entry = 0; | ||
124 | + dir->cur_entry = NULL; | ||
125 | dir->mode = (*i)->mode; | ||
126 | dir->uid = (*i)->uid; | ||
127 | dir->guid = (*i)->gid; | ||
128 | @@ -444,19 +444,20 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
129 | "%d:%d, type %d\n", dire->name, | ||
130 | dirh.start_block, dire->offset, dire->type); | ||
131 | |||
132 | - if((dir->dir_count % DIR_ENT_SIZE) == 0) { | ||
133 | - new_dir = realloc(dir->dirs, (dir->dir_count + | ||
134 | - DIR_ENT_SIZE) * sizeof(struct dir_ent)); | ||
135 | - if(new_dir == NULL) | ||
136 | - MEM_ERROR(); | ||
137 | - dir->dirs = new_dir; | ||
138 | - } | ||
139 | + ent = malloc(sizeof(struct dir_ent)); | ||
140 | + if(ent == NULL) | ||
141 | + MEM_ERROR(); | ||
142 | |||
143 | - dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
144 | - dir->dirs[dir->dir_count].start_block = | ||
145 | - dirh.start_block; | ||
146 | - dir->dirs[dir->dir_count].offset = dire->offset; | ||
147 | - dir->dirs[dir->dir_count].type = dire->type; | ||
148 | + ent->name = strdup(dire->name); | ||
149 | + ent->start_block = dirh.start_block; | ||
150 | + ent->offset = dire->offset; | ||
151 | + ent->type = dire->type; | ||
152 | + ent->next = NULL; | ||
153 | + if(cur_ent == NULL) | ||
154 | + dir->dirs = ent; | ||
155 | + else | ||
156 | + cur_ent->next = ent; | ||
157 | + cur_ent = ent; | ||
158 | dir->dir_count ++; | ||
159 | bytes += dire->size + 1; | ||
160 | } | ||
161 | diff --git a/squashfs-tools/unsquash-3.c b/squashfs-tools/unsquash-3.c | ||
162 | index 8223f27..835a574 100644 | ||
163 | --- a/squashfs-tools/unsquash-3.c | ||
164 | +++ b/squashfs-tools/unsquash-3.c | ||
165 | @@ -381,7 +381,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
166 | long long start; | ||
167 | int bytes = 0; | ||
168 | int dir_count, size, res; | ||
169 | - struct dir_ent *new_dir; | ||
170 | + struct dir_ent *ent, *cur_ent = NULL; | ||
171 | struct dir *dir; | ||
172 | |||
173 | TRACE("squashfs_opendir: inode start block %d, offset %d\n", | ||
174 | @@ -394,7 +394,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
175 | MEM_ERROR(); | ||
176 | |||
177 | dir->dir_count = 0; | ||
178 | - dir->cur_entry = 0; | ||
179 | + dir->cur_entry = NULL; | ||
180 | dir->mode = (*i)->mode; | ||
181 | dir->uid = (*i)->uid; | ||
182 | dir->guid = (*i)->gid; | ||
183 | @@ -478,19 +478,20 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
184 | "%d:%d, type %d\n", dire->name, | ||
185 | dirh.start_block, dire->offset, dire->type); | ||
186 | |||
187 | - if((dir->dir_count % DIR_ENT_SIZE) == 0) { | ||
188 | - new_dir = realloc(dir->dirs, (dir->dir_count + | ||
189 | - DIR_ENT_SIZE) * sizeof(struct dir_ent)); | ||
190 | - if(new_dir == NULL) | ||
191 | - MEM_ERROR(); | ||
192 | - dir->dirs = new_dir; | ||
193 | - } | ||
194 | + ent = malloc(sizeof(struct dir_ent)); | ||
195 | + if(ent == NULL) | ||
196 | + MEM_ERROR(); | ||
197 | |||
198 | - dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
199 | - dir->dirs[dir->dir_count].start_block = | ||
200 | - dirh.start_block; | ||
201 | - dir->dirs[dir->dir_count].offset = dire->offset; | ||
202 | - dir->dirs[dir->dir_count].type = dire->type; | ||
203 | + ent->name = strdup(dire->name); | ||
204 | + ent->start_block = dirh.start_block; | ||
205 | + ent->offset = dire->offset; | ||
206 | + ent->type = dire->type; | ||
207 | + ent->next = NULL; | ||
208 | + if(cur_ent == NULL) | ||
209 | + dir->dirs = ent; | ||
210 | + else | ||
211 | + cur_ent->next = ent; | ||
212 | + cur_ent = ent; | ||
213 | dir->dir_count ++; | ||
214 | bytes += dire->size + 1; | ||
215 | } | ||
216 | diff --git a/squashfs-tools/unsquash-4.c b/squashfs-tools/unsquash-4.c | ||
217 | index 1e199a7..694783d 100644 | ||
218 | --- a/squashfs-tools/unsquash-4.c | ||
219 | +++ b/squashfs-tools/unsquash-4.c | ||
220 | @@ -331,7 +331,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
221 | struct squashfs_dir_entry *dire = (struct squashfs_dir_entry *) buffer; | ||
222 | long long start; | ||
223 | int bytes = 0, dir_count, size, res; | ||
224 | - struct dir_ent *new_dir; | ||
225 | + struct dir_ent *ent, *cur_ent = NULL; | ||
226 | struct dir *dir; | ||
227 | |||
228 | TRACE("squashfs_opendir: inode start block %d, offset %d\n", | ||
229 | @@ -344,7 +344,7 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
230 | MEM_ERROR(); | ||
231 | |||
232 | dir->dir_count = 0; | ||
233 | - dir->cur_entry = 0; | ||
234 | + dir->cur_entry = NULL; | ||
235 | dir->mode = (*i)->mode; | ||
236 | dir->uid = (*i)->uid; | ||
237 | dir->guid = (*i)->gid; | ||
238 | @@ -415,19 +415,20 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
239 | "%d:%d, type %d\n", dire->name, | ||
240 | dirh.start_block, dire->offset, dire->type); | ||
241 | |||
242 | - if((dir->dir_count % DIR_ENT_SIZE) == 0) { | ||
243 | - new_dir = realloc(dir->dirs, (dir->dir_count + | ||
244 | - DIR_ENT_SIZE) * sizeof(struct dir_ent)); | ||
245 | - if(new_dir == NULL) | ||
246 | - MEM_ERROR(); | ||
247 | - dir->dirs = new_dir; | ||
248 | - } | ||
249 | + ent = malloc(sizeof(struct dir_ent)); | ||
250 | + if(ent == NULL) | ||
251 | + MEM_ERROR(); | ||
252 | |||
253 | - dir->dirs[dir->dir_count].name = strdup(dire->name); | ||
254 | - dir->dirs[dir->dir_count].start_block = | ||
255 | - dirh.start_block; | ||
256 | - dir->dirs[dir->dir_count].offset = dire->offset; | ||
257 | - dir->dirs[dir->dir_count].type = dire->type; | ||
258 | + ent->name = strdup(dire->name); | ||
259 | + ent->start_block = dirh.start_block; | ||
260 | + ent->offset = dire->offset; | ||
261 | + ent->type = dire->type; | ||
262 | + ent->next = NULL; | ||
263 | + if(cur_ent == NULL) | ||
264 | + dir->dirs = ent; | ||
265 | + else | ||
266 | + cur_ent->next = ent; | ||
267 | + cur_ent = ent; | ||
268 | dir->dir_count ++; | ||
269 | bytes += dire->size + 1; | ||
270 | } | ||
271 | diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c | ||
272 | index 04be53c..fee28ec 100644 | ||
273 | --- a/squashfs-tools/unsquashfs.c | ||
274 | +++ b/squashfs-tools/unsquashfs.c | ||
275 | @@ -1337,14 +1337,18 @@ failed: | ||
276 | int squashfs_readdir(struct dir *dir, char **name, unsigned int *start_block, | ||
277 | unsigned int *offset, unsigned int *type) | ||
278 | { | ||
279 | - if(dir->cur_entry == dir->dir_count) | ||
280 | + if(dir->cur_entry == NULL) | ||
281 | + dir->cur_entry = dir->dirs; | ||
282 | + else | ||
283 | + dir->cur_entry = dir->cur_entry->next; | ||
284 | + | ||
285 | + if(dir->cur_entry == NULL) | ||
286 | return FALSE; | ||
287 | |||
288 | - *name = dir->dirs[dir->cur_entry].name; | ||
289 | - *start_block = dir->dirs[dir->cur_entry].start_block; | ||
290 | - *offset = dir->dirs[dir->cur_entry].offset; | ||
291 | - *type = dir->dirs[dir->cur_entry].type; | ||
292 | - dir->cur_entry ++; | ||
293 | + *name = dir->cur_entry->name; | ||
294 | + *start_block = dir->cur_entry->start_block; | ||
295 | + *offset = dir->cur_entry->offset; | ||
296 | + *type = dir->cur_entry->type; | ||
297 | |||
298 | return TRUE; | ||
299 | } | ||
300 | diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h | ||
301 | index 583fbe4..f8cf78c 100644 | ||
302 | --- a/squashfs-tools/unsquashfs.h | ||
303 | +++ b/squashfs-tools/unsquashfs.h | ||
304 | @@ -168,17 +168,18 @@ struct dir_ent { | ||
305 | unsigned int start_block; | ||
306 | unsigned int offset; | ||
307 | unsigned int type; | ||
308 | + struct dir_ent *next; | ||
309 | }; | ||
310 | |||
311 | struct dir { | ||
312 | int dir_count; | ||
313 | - int cur_entry; | ||
314 | unsigned int mode; | ||
315 | uid_t uid; | ||
316 | gid_t guid; | ||
317 | unsigned int mtime; | ||
318 | unsigned int xattr; | ||
319 | struct dir_ent *dirs; | ||
320 | + struct dir_ent *cur_entry; | ||
321 | }; | ||
322 | |||
323 | struct file_entry { | ||
324 | -- | ||
325 | 2.17.1 | ||
326 | |||
diff --git a/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072.patch b/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072.patch deleted file mode 100644 index f807af60bc..0000000000 --- a/meta/recipes-devtools/squashfs-tools/squashfs-tools/CVE-2021-41072.patch +++ /dev/null | |||
@@ -1,329 +0,0 @@ | |||
1 | CVE: CVE-2021-41072 | ||
2 | Upstream-Status: Backport [https://github.com/plougher/squashfs-tools/commit/e048580] | ||
3 | |||
4 | Update on 20211109: | ||
5 | Squash a follow-up fix for CVE-2021-41072 from upstream: | ||
6 | https://github.com/plougher/squashfs-tools/commit/19fcc93 | ||
7 | |||
8 | Signed-off-by: Kai Kang <kai.kang@windriver.com> | ||
9 | |||
10 | From e0485802ec72996c20026da320650d8362f555bd Mon Sep 17 00:00:00 2001 | ||
11 | From: Phillip Lougher <phillip@squashfs.org.uk> | ||
12 | Date: Sun, 12 Sep 2021 23:50:06 +0100 | ||
13 | Subject: [PATCH] Unsquashfs: additional write outside destination directory | ||
14 | exploit fix | ||
15 | |||
16 | An issue on github (https://github.com/plougher/squashfs-tools/issues/72) | ||
17 | showed how some specially crafted Squashfs filesystems containing | ||
18 | invalid file names (with '/' and '..') can cause Unsquashfs to write | ||
19 | files outside of the destination directory. | ||
20 | |||
21 | Since then it has been shown that specially crafted Squashfs filesystems | ||
22 | that contain a symbolic link pointing outside of the destination directory, | ||
23 | coupled with an identically named file within the same directory, can | ||
24 | cause Unsquashfs to write files outside of the destination directory. | ||
25 | |||
26 | Specifically the symbolic link produces a pathname pointing outside | ||
27 | of the destination directory, which is then followed when writing the | ||
28 | duplicate identically named file within the directory. | ||
29 | |||
30 | This commit fixes this exploit by explictly checking for duplicate | ||
31 | filenames within a directory. As directories in v2.1, v3.x, and v4.0 | ||
32 | filesystems are sorted, this is achieved by checking for consecutively | ||
33 | identical filenames. Additionally directories are checked to | ||
34 | ensure they are sorted, to avoid attempts to evade the duplicate | ||
35 | check. | ||
36 | |||
37 | Version 1.x and 2.0 filesystems (where the directories were unsorted) | ||
38 | are sorted and then the above duplicate filename check is applied. | ||
39 | |||
40 | Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk> | ||
41 | --- | ||
42 | squashfs-tools/Makefile | 6 +- | ||
43 | squashfs-tools/unsquash-1.c | 6 ++ | ||
44 | squashfs-tools/unsquash-12.c | 110 +++++++++++++++++++++++++++++++++ | ||
45 | squashfs-tools/unsquash-1234.c | 21 +++++++ | ||
46 | squashfs-tools/unsquash-2.c | 16 +++++ | ||
47 | squashfs-tools/unsquash-3.c | 6 ++ | ||
48 | squashfs-tools/unsquash-4.c | 6 ++ | ||
49 | squashfs-tools/unsquashfs.h | 4 ++ | ||
50 | 8 files changed, 173 insertions(+), 2 deletions(-) | ||
51 | create mode 100644 squashfs-tools/unsquash-12.c | ||
52 | |||
53 | diff --git a/squashfs-tools/Makefile b/squashfs-tools/Makefile | ||
54 | index 7262a2e..1b544ed 100755 | ||
55 | --- a/squashfs-tools/Makefile | ||
56 | +++ b/squashfs-tools/Makefile | ||
57 | @@ -160,8 +160,8 @@ MKSQUASHFS_OBJS = mksquashfs.o read_fs.o action.o swap.o pseudo.o compressor.o \ | ||
58 | caches-queues-lists.o reader.o tar.o | ||
59 | |||
60 | UNSQUASHFS_OBJS = unsquashfs.o unsquash-1.o unsquash-2.o unsquash-3.o \ | ||
61 | - unsquash-4.o unsquash-123.o unsquash-34.o unsquash-1234.o swap.o \ | ||
62 | - compressor.o unsquashfs_info.o | ||
63 | + unsquash-4.o unsquash-123.o unsquash-34.o unsquash-1234.o unsquash-12.o \ | ||
64 | + swap.o compressor.o unsquashfs_info.o | ||
65 | |||
66 | CFLAGS ?= -O2 | ||
67 | CFLAGS += $(EXTRA_CFLAGS) $(INCLUDEDIR) -D_FILE_OFFSET_BITS=64 \ | ||
68 | @@ -393,6 +393,8 @@ unsquash-34.o: unsquashfs.h unsquash-34.c unsquashfs_error.h | ||
69 | |||
70 | unsquash-1234.o: unsquash-1234.c unsquashfs_error.h | ||
71 | |||
72 | +unsquash-12.o: unsquash-12.c unsquashfs.h | ||
73 | + | ||
74 | unsquashfs_xattr.o: unsquashfs_xattr.c unsquashfs.h squashfs_fs.h xattr.h unsquashfs_error.h | ||
75 | |||
76 | unsquashfs_info.o: unsquashfs.h squashfs_fs.h unsquashfs_error.h | ||
77 | diff --git a/squashfs-tools/unsquash-1.c b/squashfs-tools/unsquash-1.c | ||
78 | index b604434..88866fc 100644 | ||
79 | --- a/squashfs-tools/unsquash-1.c | ||
80 | +++ b/squashfs-tools/unsquash-1.c | ||
81 | @@ -370,6 +370,12 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
82 | } | ||
83 | } | ||
84 | |||
85 | + /* check directory for duplicate names. Need to sort directory first */ | ||
86 | + sort_directory(dir); | ||
87 | + if(check_directory(dir) == FALSE) { | ||
88 | + ERROR("File system corrupted: directory has duplicate names\n"); | ||
89 | + goto corrupted; | ||
90 | + } | ||
91 | return dir; | ||
92 | |||
93 | corrupted: | ||
94 | diff --git a/squashfs-tools/unsquash-12.c b/squashfs-tools/unsquash-12.c | ||
95 | new file mode 100644 | ||
96 | index 0000000..61bf128 | ||
97 | --- /dev/null | ||
98 | +++ b/squashfs-tools/unsquash-12.c | ||
99 | @@ -0,0 +1,110 @@ | ||
100 | +/* | ||
101 | + * Unsquash a squashfs filesystem. This is a highly compressed read only | ||
102 | + * filesystem. | ||
103 | + * | ||
104 | + * Copyright (c) 2021 | ||
105 | + * Phillip Lougher <phillip@squashfs.org.uk> | ||
106 | + * | ||
107 | + * This program is free software; you can redistribute it and/or | ||
108 | + * modify it under the terms of the GNU General Public License | ||
109 | + * as published by the Free Software Foundation; either version 2, | ||
110 | + * or (at your option) any later version. | ||
111 | + * | ||
112 | + * This program is distributed in the hope that it will be useful, | ||
113 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
114 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
115 | + * GNU General Public License for more details. | ||
116 | + * | ||
117 | + * You should have received a copy of the GNU General Public License | ||
118 | + * along with this program; if not, write to the Free Software | ||
119 | + * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
120 | + * | ||
121 | + * unsquash-12.c | ||
122 | + * | ||
123 | + * Helper functions used by unsquash-1 and unsquash-2. | ||
124 | + */ | ||
125 | + | ||
126 | +#include "unsquashfs.h" | ||
127 | + | ||
128 | +/* | ||
129 | + * Bottom up linked list merge sort. | ||
130 | + * | ||
131 | + */ | ||
132 | +void sort_directory(struct dir *dir) | ||
133 | +{ | ||
134 | + struct dir_ent *cur, *l1, *l2, *next; | ||
135 | + int len1, len2, stride = 1; | ||
136 | + | ||
137 | + if(dir->dir_count < 2) | ||
138 | + return; | ||
139 | + | ||
140 | + /* | ||
141 | + * We can consider our linked-list to be made up of stride length | ||
142 | + * sublists. Eacn iteration around this loop merges adjacent | ||
143 | + * stride length sublists into larger 2*stride sublists. We stop | ||
144 | + * when stride becomes equal to the entire list. | ||
145 | + * | ||
146 | + * Initially stride = 1 (by definition a sublist of 1 is sorted), and | ||
147 | + * these 1 element sublists are merged into 2 element sublists, which | ||
148 | + * are then merged into 4 element sublists and so on. | ||
149 | + */ | ||
150 | + do { | ||
151 | + l2 = dir->dirs; /* head of current linked list */ | ||
152 | + cur = NULL; /* empty output list */ | ||
153 | + | ||
154 | + /* | ||
155 | + * Iterate through the linked list, merging adjacent sublists. | ||
156 | + * On each interation l2 points to the next sublist pair to be | ||
157 | + * merged (if there's only one sublist left this is simply added | ||
158 | + * to the output list) | ||
159 | + */ | ||
160 | + while(l2) { | ||
161 | + l1 = l2; | ||
162 | + for(len1 = 0; l2 && len1 < stride; len1 ++, l2 = l2->next); | ||
163 | + len2 = stride; | ||
164 | + | ||
165 | + /* | ||
166 | + * l1 points to first sublist. | ||
167 | + * l2 points to second sublist. | ||
168 | + * Merge them onto the output list | ||
169 | + */ | ||
170 | + while(len1 && l2 && len2) { | ||
171 | + if(strcmp(l1->name, l2->name) <= 0) { | ||
172 | + next = l1; | ||
173 | + l1 = l1->next; | ||
174 | + len1 --; | ||
175 | + } else { | ||
176 | + next = l2; | ||
177 | + l2 = l2->next; | ||
178 | + len2 --; | ||
179 | + } | ||
180 | + | ||
181 | + if(cur) { | ||
182 | + cur->next = next; | ||
183 | + cur = next; | ||
184 | + } else | ||
185 | + dir->dirs = cur = next; | ||
186 | + } | ||
187 | + /* | ||
188 | + * One sublist is now empty, copy the other one onto the | ||
189 | + * output list | ||
190 | + */ | ||
191 | + for(; len1; len1 --, l1 = l1->next) { | ||
192 | + if(cur) { | ||
193 | + cur->next = l1; | ||
194 | + cur = l1; | ||
195 | + } else | ||
196 | + dir->dirs = cur = l1; | ||
197 | + } | ||
198 | + for(; l2 && len2; len2 --, l2 = l2->next) { | ||
199 | + if(cur) { | ||
200 | + cur->next = l2; | ||
201 | + cur = l2; | ||
202 | + } else | ||
203 | + dir->dirs = cur = l2; | ||
204 | + } | ||
205 | + } | ||
206 | + cur->next = NULL; | ||
207 | + stride = stride << 1; | ||
208 | + } while(stride < dir->dir_count); | ||
209 | +} | ||
210 | diff --git a/squashfs-tools/unsquash-1234.c b/squashfs-tools/unsquash-1234.c | ||
211 | index e389f8d..98a81ed 100644 | ||
212 | --- a/squashfs-tools/unsquash-1234.c | ||
213 | +++ b/squashfs-tools/unsquash-1234.c | ||
214 | @@ -72,3 +72,24 @@ void squashfs_closedir(struct dir *dir) | ||
215 | |||
216 | free(dir); | ||
217 | } | ||
218 | + | ||
219 | + | ||
220 | +/* | ||
221 | + * Check directory for duplicate names. As the directory should be sorted, | ||
222 | + * duplicates will be consecutive. Obviously we also need to check if the | ||
223 | + * directory has been deliberately unsorted, to evade this check. | ||
224 | + */ | ||
225 | +int check_directory(struct dir *dir) | ||
226 | +{ | ||
227 | + int i; | ||
228 | + struct dir_ent *ent; | ||
229 | + | ||
230 | + if(dir->dir_count < 2) | ||
231 | + return TRUE; | ||
232 | + | ||
233 | + for(ent = dir->dirs, i = 0; i < dir->dir_count - 1; ent = ent->next, i++) | ||
234 | + if(strcmp(ent->name, ent->next->name) >= 0) | ||
235 | + return FALSE; | ||
236 | + | ||
237 | + return TRUE; | ||
238 | +} | ||
239 | diff --git a/squashfs-tools/unsquash-2.c b/squashfs-tools/unsquash-2.c | ||
240 | index 956f96f..0e36f7d 100644 | ||
241 | --- a/squashfs-tools/unsquash-2.c | ||
242 | +++ b/squashfs-tools/unsquash-2.c | ||
243 | @@ -29,6 +29,7 @@ | ||
244 | static squashfs_fragment_entry_2 *fragment_table; | ||
245 | static unsigned int *uid_table, *guid_table; | ||
246 | static squashfs_operations ops; | ||
247 | +static int needs_sorting = FALSE; | ||
248 | |||
249 | |||
250 | static void read_block_list(unsigned int *block_list, long long start, | ||
251 | @@ -463,6 +464,17 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
252 | } | ||
253 | } | ||
254 | |||
255 | + if(needs_sorting) | ||
256 | + sort_directory(dir); | ||
257 | + | ||
258 | + /* check directory for duplicate names and sorting */ | ||
259 | + if(check_directory(dir) == FALSE) { | ||
260 | + if(needs_sorting) | ||
261 | + ERROR("File system corrupted: directory has duplicate names\n"); | ||
262 | + else | ||
263 | + ERROR("File system corrupted: directory has duplicate names or is unsorted\n"); | ||
264 | + goto corrupted; | ||
265 | + } | ||
266 | return dir; | ||
267 | |||
268 | corrupted: | ||
269 | @@ -596,6 +608,10 @@ int read_super_2(squashfs_operations **s_ops, void *s) | ||
270 | * 2.x filesystems use gzip compression. | ||
271 | */ | ||
272 | comp = lookup_compressor("gzip"); | ||
273 | + | ||
274 | + if(sBlk_3->s_minor == 0) | ||
275 | + needs_sorting = TRUE; | ||
276 | + | ||
277 | return TRUE; | ||
278 | } | ||
279 | |||
280 | diff --git a/squashfs-tools/unsquash-3.c b/squashfs-tools/unsquash-3.c | ||
281 | index 835a574..0123562 100644 | ||
282 | --- a/squashfs-tools/unsquash-3.c | ||
283 | +++ b/squashfs-tools/unsquash-3.c | ||
284 | @@ -497,6 +497,12 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
285 | } | ||
286 | } | ||
287 | |||
288 | + /* check directory for duplicate names and sorting */ | ||
289 | + if(check_directory(dir) == FALSE) { | ||
290 | + ERROR("File system corrupted: directory has duplicate names or is unsorted\n"); | ||
291 | + goto corrupted; | ||
292 | + } | ||
293 | + | ||
294 | return dir; | ||
295 | |||
296 | corrupted: | ||
297 | diff --git a/squashfs-tools/unsquash-4.c b/squashfs-tools/unsquash-4.c | ||
298 | index 694783d..c615bb8 100644 | ||
299 | --- a/squashfs-tools/unsquash-4.c | ||
300 | +++ b/squashfs-tools/unsquash-4.c | ||
301 | @@ -434,6 +434,12 @@ static struct dir *squashfs_opendir(unsigned int block_start, unsigned int offse | ||
302 | } | ||
303 | } | ||
304 | |||
305 | + /* check directory for duplicate names and sorting */ | ||
306 | + if(check_directory(dir) == FALSE) { | ||
307 | + ERROR("File system corrupted: directory has duplicate names or is unsorted\n"); | ||
308 | + goto corrupted; | ||
309 | + } | ||
310 | + | ||
311 | return dir; | ||
312 | |||
313 | corrupted: | ||
314 | diff --git a/squashfs-tools/unsquashfs.h b/squashfs-tools/unsquashfs.h | ||
315 | index f8cf78c..bf2a80d 100644 | ||
316 | --- a/squashfs-tools/unsquashfs.h | ||
317 | +++ b/squashfs-tools/unsquashfs.h | ||
318 | @@ -293,4 +293,8 @@ extern long long *alloc_index_table(int); | ||
319 | /* unsquash-1234.c */ | ||
320 | extern int check_name(char *, int); | ||
321 | extern void squashfs_closedir(struct dir *); | ||
322 | +extern int check_directory(struct dir *); | ||
323 | + | ||
324 | +/* unsquash-12.c */ | ||
325 | +extern void sort_directory(struct dir *); | ||
326 | #endif | ||
327 | -- | ||
328 | 2.17.1 | ||
329 | |||