Browse code

Adds fix to EGG parser preventing dereference of filename if not set.

Micah Snyder authored on 2019/08/13 23:52:18
Showing 1 changed files
... ...
@@ -1560,7 +1560,7 @@ static cl_error_t egg_parse_file_extra_field(egg_handle* handle, egg_file* eggFi
1560 1560
             windowsFileInformation          = (windows_file_information*)index;
1561 1561
             eggFile->windowsFileInformation = windowsFileInformation;
1562 1562
 
1563
-            cli_dbgmsg("egg_parse_file_extra_field: windows_file_information->last_modified_time:   %016llx\n", le64_to_host(windowsFileInformation->last_modified_time));
1563
+            cli_dbgmsg("egg_parse_file_extra_field: windows_file_information->last_modified_time:   %016" PRIx64 "\n", le64_to_host(windowsFileInformation->last_modified_time));
1564 1564
             cli_dbgmsg("egg_parse_file_extra_field: windows_file_information->attribute:            %08x\n", windowsFileInformation->attribute);
1565 1565
             break;
1566 1566
         }
... ...
@@ -1592,7 +1592,7 @@ static cl_error_t egg_parse_file_extra_field(egg_handle* handle, egg_file* eggFi
1592 1592
 
1593 1593
             cli_dbgmsg("egg_parse_file_extra_field: posix_file_information->uid:                  %08x\n", le32_to_host(posixFileInformation->uid));
1594 1594
             cli_dbgmsg("egg_parse_file_extra_field: posix_file_information->gid:                  %08x\n", le32_to_host(posixFileInformation->gid));
1595
-            cli_dbgmsg("egg_parse_file_extra_field: posix_file_information->last_modified_time:   %016llx\n", le64_to_host(posixFileInformation->last_modified_time));
1595
+            cli_dbgmsg("egg_parse_file_extra_field: posix_file_information->last_modified_time:   %016" PRIx64 "\n", le64_to_host(posixFileInformation->last_modified_time));
1596 1596
             break;
1597 1597
         }
1598 1598
         case FILE_HEADER_MAGIC: {
... ...
@@ -1667,7 +1667,7 @@ static cl_error_t egg_parse_file_headers(egg_handle* handle, egg_file** file)
1667 1667
 
1668 1668
     cli_dbgmsg("egg_parse_file_headers: file_header->magic:       %08x (%s)\n", le32_to_host(fileHeader->magic), getMagicHeaderName(le32_to_host(fileHeader->magic)));
1669 1669
     cli_dbgmsg("egg_parse_file_headers: file_header->file_id:     %08x\n", le32_to_host(fileHeader->file_id));
1670
-    cli_dbgmsg("egg_parse_file_headers: file_header->file_length: %016llx (%llu)\n",
1670
+    cli_dbgmsg("egg_parse_file_headers: file_header->file_length: %016" PRIx64 " (%" PRIu64 ")\n",
1671 1671
                le64_to_host(fileHeader->file_length),
1672 1672
                le64_to_host(fileHeader->file_length));
1673 1673
 
... ...
@@ -2148,6 +2148,11 @@ cl_error_t cli_egg_peek_file_header(void* hArchive, cl_egg_metadata* file_metada
2148 2148
         goto done;
2149 2149
     }
2150 2150
 
2151
+    if (NULL == currFile->filename.name_utf8) {
2152
+        cli_errmsg("cli_egg_extract_file: egg_file is missing filename!\n");
2153
+        goto done;
2154
+    }
2155
+
2151 2156
     if (handle->bSolid) {
2152 2157
         /*
2153 2158
          * TODO: Add support for extracting files from solid archives.
... ...
@@ -2583,6 +2588,11 @@ cl_error_t cli_egg_extract_file(void* hArchive, const char** filename, const cha
2583 2583
         goto done;
2584 2584
     }
2585 2585
 
2586
+    if (NULL == currFile->filename.name_utf8) {
2587
+        cli_errmsg("cli_egg_extract_file: egg_file is missing filename!\n");
2588
+        goto done;
2589
+    }
2590
+
2586 2591
     if (handle->bSolid) {
2587 2592
         /*
2588 2593
          * TODO: Add support for extracting files from solid archives.
... ...
@@ -2627,7 +2637,7 @@ cl_error_t cli_egg_extract_file(void* hArchive, const char** filename, const cha
2627 2627
                     }
2628 2628
                     decompressed_tmp = cli_realloc(decompressed, (size_t)decompressed_size + currBlock->blockHeader->compress_size);
2629 2629
                     if (NULL == decompressed_tmp) {
2630
-                        cli_errmsg("cli_egg_extract_file: Failed to allocate %llu bytes for decompressed file!\n",
2630
+                        cli_errmsg("cli_egg_extract_file: Failed to allocate %" PRIu64 " bytes for decompressed file!\n",
2631 2631
                                    decompressed_size);
2632 2632
                         status = CL_EMEM;
2633 2633
                         goto done;
... ...
@@ -2655,7 +2665,7 @@ cl_error_t cli_egg_extract_file(void* hArchive, const char** filename, const cha
2655 2655
                     /* Decompressed block. Add it to the file data */
2656 2656
                     decompressed_tmp = cli_realloc(decompressed, (size_t)decompressed_size + decompressed_block_size);
2657 2657
                     if (NULL == decompressed_tmp) {
2658
-                        cli_errmsg("cli_egg_extract_file: Failed to allocate %llu bytes for decompressed file!\n",
2658
+                        cli_errmsg("cli_egg_extract_file: Failed to allocate %" PRIu64 " bytes for decompressed file!\n",
2659 2659
                                    decompressed_size);
2660 2660
                         free(decompressed_block);
2661 2661
                         status = CL_EMEM;
... ...
@@ -2687,7 +2697,7 @@ cl_error_t cli_egg_extract_file(void* hArchive, const char** filename, const cha
2687 2687
                     /* Decompressed block. Add it to the file data */
2688 2688
                     decompressed_tmp = cli_realloc(decompressed, (size_t)decompressed_size + decompressed_block_size);
2689 2689
                     if (NULL == decompressed_tmp) {
2690
-                        cli_errmsg("cli_egg_extract_file: Failed to allocate %llu bytes for decompressed file!\n",
2690
+                        cli_errmsg("cli_egg_extract_file: Failed to allocate %" PRIu64 " bytes for decompressed file!\n",
2691 2691
                                    decompressed_size);
2692 2692
                         free(decompressed_block);
2693 2693
                         status = CL_EMEM;
... ...
@@ -2729,7 +2739,7 @@ cl_error_t cli_egg_extract_file(void* hArchive, const char** filename, const cha
2729 2729
                     // /* Decompressed block. Add it to the file data */
2730 2730
                     // decompressed_tmp = cli_realloc(decompressed, (size_t)decompressed_size + decompressed_block_size);
2731 2731
                     // if (NULL == decompressed_tmp) {
2732
-                    //     cli_errmsg("cli_egg_extract_file: Failed to allocate %llu bytes for decompressed file!\n",
2732
+                    //     cli_errmsg("cli_egg_extract_file: Failed to allocate %" PRIu64 " bytes for decompressed file!\n",
2733 2733
                     //                decompressed_size);
2734 2734
                     //     free(decompressed_block);
2735 2735
                     //     status = CL_EMEM;
... ...
@@ -2759,7 +2769,7 @@ cl_error_t cli_egg_extract_file(void* hArchive, const char** filename, const cha
2759 2759
 
2760 2760
             if ((i == currFile->nBlocks - 1) &&                       // last block ?
2761 2761
                 (decompressed_size != currFile->file->file_length)) { // right amount of data ?
2762
-                cli_warnmsg("cli_egg_extract_file: alleged filesize (%llu) != actual filesize (%llu)!\n",
2762
+                cli_warnmsg("cli_egg_extract_file: alleged filesize (%" PRIu64 ") != actual filesize (%" PRIu64 ")!\n",
2763 2763
                             currFile->file->file_length,
2764 2764
                             decompressed_size);
2765 2765
             }