You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

474 lines
14 KiB

  1. diff -aurp a/squashfs-tools/unsquash-1.c b/squashfs-tools/unsquash-1.c
  2. --- a/squashfs-tools/unsquash-1.c 2014-09-18 20:16:18.000000000 -0600
  3. +++ b/squashfs-tools/unsquash-1.c 2017-08-29 13:18:14.403020644 -0600
  4. @@ -332,17 +332,19 @@ int read_uids_guids_1()
  5. guid_table = uid_table + sBlk.no_uids;
  6. if(swap) {
  7. - unsigned int suid_table[sBlk.no_uids + sBlk.no_guids];
  8. + unsigned int* suid_table = malloc((sBlk.no_uids + sBlk.no_guids) * sizeof(unsigned int));
  9. res = read_fs_bytes(fd, sBlk.uid_start, (sBlk.no_uids +
  10. sBlk.no_guids) * sizeof(unsigned int), suid_table);
  11. if(res == FALSE) {
  12. + free(suid_table);
  13. ERROR("read_uids_guids: failed to read uid/gid table"
  14. "\n");
  15. return FALSE;
  16. }
  17. SQUASHFS_SWAP_INTS_3(uid_table, suid_table,
  18. sBlk.no_uids + sBlk.no_guids);
  19. + free(suid_table);
  20. } else {
  21. res = read_fs_bytes(fd, sBlk.uid_start, (sBlk.no_uids +
  22. sBlk.no_guids) * sizeof(unsigned int), uid_table);
  23. diff -aurp a/squashfs-tools/unsquash-2.c b/squashfs-tools/unsquash-2.c
  24. --- a/squashfs-tools/unsquash-2.c 2014-09-18 20:16:18.000000000 -0600
  25. +++ b/squashfs-tools/unsquash-2.c 2017-08-29 13:23:48.111321548 -0600
  26. @@ -32,7 +32,7 @@ void read_block_list_2(unsigned int *blo
  27. TRACE("read_block_list: blocks %d\n", blocks);
  28. if(swap) {
  29. - unsigned int sblock_list[blocks];
  30. + unsigned int* sblock_list = malloc(blocks*sizeof(unsigned int));
  31. memcpy(sblock_list, block_ptr, blocks * sizeof(unsigned int));
  32. SQUASHFS_SWAP_INTS_3(block_list, sblock_list, blocks);
  33. } else
  34. @@ -45,7 +45,7 @@ int read_fragment_table_2(long long *dir
  35. int res, i;
  36. int bytes = SQUASHFS_FRAGMENT_BYTES_2(sBlk.s.fragments);
  37. int indexes = SQUASHFS_FRAGMENT_INDEXES_2(sBlk.s.fragments);
  38. - unsigned int fragment_table_index[indexes];
  39. + unsigned int* fragment_table_index = malloc(indexes * sizeof(unsigned int));
  40. TRACE("read_fragment_table: %d fragments, reading %d fragment indexes "
  41. "from 0x%llx\n", sBlk.s.fragments, indexes,
  42. @@ -53,6 +53,7 @@ int read_fragment_table_2(long long *dir
  43. if(sBlk.s.fragments == 0) {
  44. *directory_table_end = sBlk.s.fragment_table_start;
  45. + free(fragment_table_index);
  46. return TRUE;
  47. }
  48. @@ -62,7 +63,7 @@ int read_fragment_table_2(long long *dir
  49. "fragment table\n");
  50. if(swap) {
  51. - unsigned int sfragment_table_index[indexes];
  52. + unsigned int* sfragment_table_index = malloc(indexes * sizeof(unsigned int));
  53. res = read_fs_bytes(fd, sBlk.s.fragment_table_start,
  54. SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.s.fragments),
  55. @@ -70,10 +71,14 @@ int read_fragment_table_2(long long *dir
  56. if(res == FALSE) {
  57. ERROR("read_fragment_table: failed to read fragment "
  58. "table index\n");
  59. + free(sfragment_table_index);
  60. + free(fragment_table_index);
  61. return FALSE;
  62. }
  63. SQUASHFS_SWAP_FRAGMENT_INDEXES_2(fragment_table_index,
  64. sfragment_table_index, indexes);
  65. +
  66. + free(sfragment_table_index);
  67. } else {
  68. res = read_fs_bytes(fd, sBlk.s.fragment_table_start,
  69. SQUASHFS_FRAGMENT_INDEX_BYTES_2(sBlk.s.fragments),
  70. @@ -81,6 +86,7 @@ int read_fragment_table_2(long long *dir
  71. if(res == FALSE) {
  72. ERROR("read_fragment_table: failed to read fragment "
  73. "table index\n");
  74. + free(fragment_table_index);
  75. return FALSE;
  76. }
  77. }
  78. @@ -96,6 +102,7 @@ int read_fragment_table_2(long long *dir
  79. if(length == FALSE) {
  80. ERROR("read_fragment_table: failed to read fragment "
  81. "table block\n");
  82. + free(fragment_table_index);
  83. return FALSE;
  84. }
  85. }
  86. @@ -111,6 +118,7 @@ int read_fragment_table_2(long long *dir
  87. }
  88. *directory_table_end = fragment_table_index[0];
  89. + free(fragment_table_index);
  90. return TRUE;
  91. }
  92. diff -aurp a/squashfs-tools/unsquash-3.c b/squashfs-tools/unsquash-3.c
  93. --- a/squashfs-tools/unsquash-3.c 2014-09-18 20:16:18.000000000 -0600
  94. +++ b/squashfs-tools/unsquash-3.c 2017-08-29 14:43:17.016089289 -0600
  95. @@ -32,7 +32,7 @@ int read_fragment_table_3(long long *dir
  96. int res, i;
  97. int bytes = SQUASHFS_FRAGMENT_BYTES_3(sBlk.s.fragments);
  98. int indexes = SQUASHFS_FRAGMENT_INDEXES_3(sBlk.s.fragments);
  99. - long long fragment_table_index[indexes];
  100. + long long* fragment_table_index = malloc(indexes * sizeof(long long));
  101. TRACE("read_fragment_table: %d fragments, reading %d fragment indexes "
  102. "from 0x%llx\n", sBlk.s.fragments, indexes,
  103. @@ -40,6 +40,7 @@ int read_fragment_table_3(long long *dir
  104. if(sBlk.s.fragments == 0) {
  105. *directory_table_end = sBlk.s.fragment_table_start;
  106. + free(fragment_table_index);
  107. return TRUE;
  108. }
  109. @@ -49,7 +50,7 @@ int read_fragment_table_3(long long *dir
  110. "fragment table\n");
  111. if(swap) {
  112. - long long sfragment_table_index[indexes];
  113. + long long* sfragment_table_index = malloc(indexes * sizeof(long long));
  114. res = read_fs_bytes(fd, sBlk.s.fragment_table_start,
  115. SQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.s.fragments),
  116. @@ -57,10 +58,13 @@ int read_fragment_table_3(long long *dir
  117. if(res == FALSE) {
  118. ERROR("read_fragment_table: failed to read fragment "
  119. "table index\n");
  120. + free(fragment_table_index);
  121. + free(sfragment_table_index);
  122. return FALSE;
  123. }
  124. SQUASHFS_SWAP_FRAGMENT_INDEXES_3(fragment_table_index,
  125. sfragment_table_index, indexes);
  126. + free(sfragment_table_index);
  127. } else {
  128. res = read_fs_bytes(fd, sBlk.s.fragment_table_start,
  129. SQUASHFS_FRAGMENT_INDEX_BYTES_3(sBlk.s.fragments),
  130. @@ -68,6 +72,7 @@ int read_fragment_table_3(long long *dir
  131. if(res == FALSE) {
  132. ERROR("read_fragment_table: failed to read fragment "
  133. "table index\n");
  134. + free(fragment_table_index);
  135. return FALSE;
  136. }
  137. }
  138. @@ -83,6 +88,7 @@ int read_fragment_table_3(long long *dir
  139. if(length == FALSE) {
  140. ERROR("read_fragment_table: failed to read fragment "
  141. "table block\n");
  142. + free(fragment_table_index);
  143. return FALSE;
  144. }
  145. }
  146. @@ -98,6 +104,7 @@ int read_fragment_table_3(long long *dir
  147. }
  148. *directory_table_end = fragment_table_index[0];
  149. + free(fragment_table_index);
  150. return TRUE;
  151. }
  152. diff -aurp a/squashfs-tools/unsquash-4.c b/squashfs-tools/unsquash-4.c
  153. --- a/squashfs-tools/unsquash-4.c 2014-09-18 20:16:18.000000000 -0600
  154. +++ b/squashfs-tools/unsquash-4.c 2017-08-29 14:49:01.424441708 -0600
  155. @@ -33,7 +33,7 @@ int read_fragment_table_4(long long *dir
  156. int res, i;
  157. int bytes = SQUASHFS_FRAGMENT_BYTES(sBlk.s.fragments);
  158. int indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk.s.fragments);
  159. - long long fragment_table_index[indexes];
  160. + long long* fragment_table_index = malloc(indexes * sizeof(long long));
  161. TRACE("read_fragment_table: %d fragments, reading %d fragment indexes "
  162. "from 0x%llx\n", sBlk.s.fragments, indexes,
  163. @@ -41,6 +41,7 @@ int read_fragment_table_4(long long *dir
  164. if(sBlk.s.fragments == 0) {
  165. *directory_table_end = sBlk.s.fragment_table_start;
  166. + free(fragment_table_index);
  167. return TRUE;
  168. }
  169. @@ -55,6 +56,7 @@ int read_fragment_table_4(long long *dir
  170. if(res == FALSE) {
  171. ERROR("read_fragment_table: failed to read fragment table "
  172. "index\n");
  173. + free(fragment_table_index);
  174. return FALSE;
  175. }
  176. SQUASHFS_INSWAP_FRAGMENT_INDEXES(fragment_table_index, indexes);
  177. @@ -70,6 +72,7 @@ int read_fragment_table_4(long long *dir
  178. if(length == FALSE) {
  179. ERROR("read_fragment_table: failed to read fragment "
  180. "table index\n");
  181. + free(fragment_table_index);
  182. return FALSE;
  183. }
  184. }
  185. @@ -78,6 +81,7 @@ int read_fragment_table_4(long long *dir
  186. SQUASHFS_INSWAP_FRAGMENT_ENTRY(&fragment_table[i]);
  187. *directory_table_end = fragment_table_index[0];
  188. + free(fragment_table_index);
  189. return TRUE;
  190. }
  191. @@ -356,13 +360,14 @@ int read_uids_guids_4()
  192. int res, i;
  193. int bytes = SQUASHFS_ID_BYTES(sBlk.s.no_ids);
  194. int indexes = SQUASHFS_ID_BLOCKS(sBlk.s.no_ids);
  195. - long long id_index_table[indexes];
  196. + long long* id_index_table = malloc(indexes * sizeof(long long));
  197. TRACE("read_uids_guids: no_ids %d\n", sBlk.s.no_ids);
  198. id_table = malloc(bytes);
  199. if(id_table == NULL) {
  200. ERROR("read_uids_guids: failed to allocate id table\n");
  201. + free(id_index_table);
  202. return FALSE;
  203. }
  204. @@ -370,6 +375,7 @@ int read_uids_guids_4()
  205. SQUASHFS_ID_BLOCK_BYTES(sBlk.s.no_ids), id_index_table);
  206. if(res == FALSE) {
  207. ERROR("read_uids_guids: failed to read id index table\n");
  208. + free(id_index_table);
  209. return FALSE;
  210. }
  211. SQUASHFS_INSWAP_ID_BLOCKS(id_index_table, indexes);
  212. @@ -382,11 +388,13 @@ int read_uids_guids_4()
  213. if(res == FALSE) {
  214. ERROR("read_uids_guids: failed to read id table block"
  215. "\n");
  216. + free(id_index_table);
  217. return FALSE;
  218. }
  219. }
  220. SQUASHFS_INSWAP_INTS(id_table, sBlk.s.no_ids);
  221. + free(id_index_table);
  222. return TRUE;
  223. }
  224. diff -aurp a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c
  225. --- a/squashfs-tools/unsquashfs.c 2017-08-29 14:58:51.917037533 -0600
  226. +++ b/squashfs-tools/unsquashfs.c 2017-08-29 13:14:03.082818149 -0600
  227. @@ -691,7 +691,7 @@ int read_block(int fd, long long start,
  228. return 0;
  229. if(compressed) {
  230. - char buffer[c_byte];
  231. + char* buffer = malloc(c_byte);
  232. int error;
  233. res = read_fs_bytes(fd, start + offset, c_byte, buffer);
  234. @@ -704,8 +704,10 @@ int read_block(int fd, long long start,
  235. if(res == -1) {
  236. ERROR("%s uncompress failed with error code %d\n",
  237. comp->name, error);
  238. + free(buffer);
  239. goto failed;
  240. }
  241. + free(buffer);
  242. } else {
  243. res = read_fs_bytes(fd, start + offset, c_byte, block);
  244. if(res == FALSE)
  245. @@ -2097,7 +2099,7 @@ void *writer(void *arg)
  246. */
  247. void *inflator(void *arg)
  248. {
  249. - char tmp[block_size];
  250. + char* tmp = malloc(block_size);
  251. while(1) {
  252. struct cache_entry *entry = queue_get(to_inflate);
  253. @@ -2120,6 +2122,7 @@ void *inflator(void *arg)
  254. */
  255. cache_block_ready(entry, res == -1);
  256. }
  257. + free(tmp);
  258. }
  259. diff -aurp a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
  260. --- a/squashfs-tools/mksquashfs.c 2017-09-05 15:09:19.090937121 -0600
  261. +++ b/squashfs-tools/mksquashfs.c 2017-09-01 09:58:11.274529037 -0600
  262. @@ -652,7 +652,7 @@ long long write_directories()
  263. long long write_id_table()
  264. {
  265. unsigned int id_bytes = SQUASHFS_ID_BYTES(id_count);
  266. - unsigned int p[id_count];
  267. + unsigned int* p = malloc(id_count * sizeof(unsigned int));
  268. int i;
  269. TRACE("write_id_table: ids %d, id_bytes %d\n", id_count, id_bytes);
  270. @@ -655,6 +655,9 @@ long long write_id_table()
  271. unsigned int* p = malloc(id_count * sizeof(unsigned int));
  272. int i;
  273. + if(p == NULL)
  274. + MEM_ERROR();
  275. +
  276. TRACE("write_id_table: ids %d, id_bytes %d\n", id_count, id_bytes);
  277. for(i = 0; i < id_count; i++) {
  278. TRACE("write_id_table: id index %d, id %d", i, id_table[i]->id);
  279. @@ -661,6 +661,7 @@ long long write_id_table()
  280. SQUASHFS_SWAP_INTS(&id_table[i]->id, p + i, 1);
  281. }
  282. + free(p);
  283. return generic_write_table(id_bytes, p, 0, NULL, noI);
  284. }
  285. diff -aurp a/squashfs-tools/read_fs.c b/squashfs-tools/read_fs.c
  286. --- a/squashfs-tools/read_fs.c 2014-09-18 20:16:18.000000000 -0600
  287. +++ b/squashfs-tools/read_fs.c 2017-09-05 15:35:19.328547536 -0600
  288. @@ -77,18 +77,24 @@ int read_block(int fd, long long start,
  289. return 0;
  290. if(compressed) {
  291. - char buffer[c_byte];
  292. + char* buffer = malloc(c_byte);
  293. int error;
  294. + if(buffer == NULL)
  295. + MEM_ERROR();
  296. +
  297. res = read_fs_bytes(fd, start + 2, c_byte, buffer);
  298. - if(res == 0)
  299. + if(res == 0) {
  300. + free(buffer);
  301. return 0;
  302. + }
  303. res = compressor_uncompress(comp, block, buffer, c_byte,
  304. outlen, &error);
  305. if(res == -1) {
  306. ERROR("%s uncompress failed with error code %d\n",
  307. comp->name, error);
  308. + free(buffer);
  309. return 0;
  310. }
  311. } else {
  312. @@ -699,7 +705,7 @@ all_done:
  313. unsigned int *read_id_table(int fd, struct squashfs_super_block *sBlk)
  314. {
  315. int indexes = SQUASHFS_ID_BLOCKS(sBlk->no_ids);
  316. - long long index[indexes];
  317. + long long* index;
  318. int bytes = SQUASHFS_ID_BYTES(sBlk->no_ids);
  319. unsigned int *id_table;
  320. int res, i;
  321. @@ -708,12 +714,17 @@ unsigned int *read_id_table(int fd, stru
  322. if(id_table == NULL)
  323. MEM_ERROR();
  324. + index = malloc(indexes * sizeof(long long));
  325. + if(index == NULL)
  326. + MEM_ERROR();
  327. +
  328. res = read_fs_bytes(fd, sBlk->id_table_start,
  329. SQUASHFS_ID_BLOCK_BYTES(sBlk->no_ids), index);
  330. if(res == 0) {
  331. ERROR("Failed to read id table index\n");
  332. ERROR("Filesystem corrupted?\n");
  333. free(id_table);
  334. + free(index);
  335. return NULL;
  336. }
  337. @@ -732,6 +743,7 @@ unsigned int *read_id_table(int fd, stru
  338. "length %d\n", i, index[i], length);
  339. ERROR("Filesystem corrupted?\n");
  340. free(id_table);
  341. + free(index);
  342. return NULL;
  343. }
  344. }
  345. @@ -753,14 +765,19 @@ int read_fragment_table(int fd, struct s
  346. int res, i;
  347. int bytes = SQUASHFS_FRAGMENT_BYTES(sBlk->fragments);
  348. int indexes = SQUASHFS_FRAGMENT_INDEXES(sBlk->fragments);
  349. - long long fragment_table_index[indexes];
  350. + long long* fragment_table_index = malloc(indexes * sizeof(long long));
  351. +
  352. + if(fragment_table_index == NULL)
  353. + MEM_ERROR();
  354. TRACE("read_fragment_table: %d fragments, reading %d fragment indexes "
  355. "from 0x%llx\n", sBlk->fragments, indexes,
  356. sBlk->fragment_table_start);
  357. - if(sBlk->fragments == 0)
  358. + if(sBlk->fragments == 0) {
  359. + free(fragment_table_index);
  360. return 1;
  361. + }
  362. *fragment_table = malloc(bytes);
  363. if(*fragment_table == NULL)
  364. @@ -773,6 +790,7 @@ int read_fragment_table(int fd, struct s
  365. ERROR("Failed to read fragment table index\n");
  366. ERROR("Filesystem corrupted?\n");
  367. free(*fragment_table);
  368. + free(fragment_table_index);
  369. return 0;
  370. }
  371. @@ -792,6 +810,7 @@ int read_fragment_table(int fd, struct s
  372. fragment_table_index[i], length);
  373. ERROR("Filesystem corrupted?\n");
  374. free(*fragment_table);
  375. + free(fragment_table_index);
  376. return 0;
  377. }
  378. }
  379. @@ -799,6 +818,7 @@ int read_fragment_table(int fd, struct s
  380. for(i = 0; i < sBlk->fragments; i++)
  381. SQUASHFS_INSWAP_FRAGMENT_ENTRY(&(*fragment_table)[i]);
  382. + free(fragment_table_index);
  383. return 1;
  384. }
  385. @@ -808,11 +828,16 @@ int read_inode_lookup_table(int fd, stru
  386. {
  387. int lookup_bytes = SQUASHFS_LOOKUP_BYTES(sBlk->inodes);
  388. int indexes = SQUASHFS_LOOKUP_BLOCKS(sBlk->inodes);
  389. - long long index[indexes];
  390. + long long* index = malloc(indexes * sizeof(long long));
  391. int res, i;
  392. - if(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK)
  393. + if(index == NULL)
  394. + MEM_ERROR();
  395. +
  396. + if(sBlk->lookup_table_start == SQUASHFS_INVALID_BLK) {
  397. + free(index);
  398. return 1;
  399. + }
  400. *inode_lookup_table = malloc(lookup_bytes);
  401. if(*inode_lookup_table == NULL)
  402. @@ -824,6 +849,7 @@ int read_inode_lookup_table(int fd, stru
  403. ERROR("Failed to read inode lookup table index\n");
  404. ERROR("Filesystem corrupted?\n");
  405. free(*inode_lookup_table);
  406. + free(index);
  407. return 0;
  408. }
  409. @@ -843,12 +869,14 @@ int read_inode_lookup_table(int fd, stru
  410. length);
  411. ERROR("Filesystem corrupted?\n");
  412. free(*inode_lookup_table);
  413. + free(index);
  414. return 0;
  415. }
  416. }
  417. SQUASHFS_INSWAP_LONG_LONGS(*inode_lookup_table, sBlk->inodes);
  418. + free(index);
  419. return 1;
  420. }