Browse code

XAR: Fix minor leak, fix archive checksum creation

Fixes a error case leak that could occur if flate decompressino fails.

Adds missing xar_hash_final() call to finalize archive hash creation.

Micah Snyder authored on 2020/08/22 13:39:06
Showing 1 changed files
... ...
@@ -490,6 +490,7 @@ int cli_scanxar(cli_ctx *ctx)
490 490
     }
491 491
     rc = inflate(&strm, Z_SYNC_FLUSH);
492 492
     if (rc != Z_OK && rc != Z_STREAM_END) {
493
+        inflateEnd(&strm);
493 494
         cli_dbgmsg("cli_scanxar:inflate error %i \n", rc);
494 495
         rc = CL_EFORMAT;
495 496
         goto exit_toc;
... ...
@@ -804,14 +805,22 @@ int cli_scanxar(cli_ctx *ctx)
804 804
                 }
805 805
         } /* end of switch */
806 806
 
807
+        if (a_hash_ctx != NULL) {
808
+            xar_hash_final(a_hash_ctx, result, a_hash);
809
+            a_hash_ctx = NULL;
810
+        } else if (rc == CL_SUCCESS) {
811
+            cli_dbgmsg("cli_scanxar: archived-checksum missing.\n");
812
+            cksum_fails++;
813
+        }
814
+        if (e_hash_ctx != NULL) {
815
+            xar_hash_final(e_hash_ctx, result, e_hash);
816
+            e_hash_ctx = NULL;
817
+        } else if (rc == CL_SUCCESS) {
818
+            cli_dbgmsg("cli_scanxar: extracted-checksum(unarchived-checksum) missing.\n");
819
+            cksum_fails++;
820
+        }
821
+
807 822
         if (rc == CL_SUCCESS) {
808
-            if (a_hash_ctx != NULL) {
809
-                xar_hash_final(a_hash_ctx, result, a_hash);
810
-                a_hash_ctx = NULL;
811
-            } else {
812
-                cli_dbgmsg("cli_scanxar: archived-checksum missing.\n");
813
-                cksum_fails++;
814
-            }
815 823
             if (a_cksum != NULL) {
816 824
                 expected = cli_hex2str((char *)a_cksum);
817 825
                 if (xar_hash_check(a_hash, result, expected) != 0) {
... ...
@@ -823,13 +832,6 @@ int cli_scanxar(cli_ctx *ctx)
823 823
                 free(expected);
824 824
             }
825 825
 
826
-            if (e_hash_ctx != NULL) {
827
-                xar_hash_final(e_hash_ctx, result, e_hash);
828
-                e_hash_ctx = NULL;
829
-            } else {
830
-                cli_dbgmsg("cli_scanxar: extracted-checksum(unarchived-checksum) missing.\n");
831
-                cksum_fails++;
832
-            }
833 826
             if (e_cksum != NULL) {
834 827
                 if (do_extract_cksum) {
835 828
                     expected = cli_hex2str((char *)e_cksum);