Browse code

XAR: Fix hash result over-write issue

Micah Snyder authored on 2020/08/28 12:42:43
Showing 1 changed files
... ...
@@ -437,7 +437,8 @@ int cli_scanxar(cli_ctx *ctx)
437 437
     int a_hash, e_hash;
438 438
     unsigned char *a_cksum = NULL, *e_cksum = NULL;
439 439
     void *a_hash_ctx = NULL, *e_hash_ctx = NULL;
440
-    char result[SHA1_HASH_SIZE];
440
+    char e_hash_result[SHA1_HASH_SIZE];
441
+    char a_hash_result[SHA1_HASH_SIZE];
441 442
 
442 443
     memset(&strm, 0x00, sizeof(z_stream));
443 444
 
... ...
@@ -806,14 +807,14 @@ int cli_scanxar(cli_ctx *ctx)
806 806
         } /* end of switch */
807 807
 
808 808
         if (a_hash_ctx != NULL) {
809
-            xar_hash_final(a_hash_ctx, result, a_hash);
809
+            xar_hash_final(a_hash_ctx, a_hash_result, a_hash);
810 810
             a_hash_ctx = NULL;
811 811
         } else if (rc == CL_SUCCESS) {
812 812
             cli_dbgmsg("cli_scanxar: archived-checksum missing.\n");
813 813
             cksum_fails++;
814 814
         }
815 815
         if (e_hash_ctx != NULL) {
816
-            xar_hash_final(e_hash_ctx, result, e_hash);
816
+            xar_hash_final(e_hash_ctx, e_hash_result, e_hash);
817 817
             e_hash_ctx = NULL;
818 818
         } else if (rc == CL_SUCCESS) {
819 819
             cli_dbgmsg("cli_scanxar: extracted-checksum(unarchived-checksum) missing.\n");
... ...
@@ -823,7 +824,7 @@ int cli_scanxar(cli_ctx *ctx)
823 823
         if (rc == CL_SUCCESS) {
824 824
             if (a_cksum != NULL) {
825 825
                 expected = cli_hex2str((char *)a_cksum);
826
-                if (xar_hash_check(a_hash, result, expected) != 0) {
826
+                if (xar_hash_check(a_hash, a_hash_result, expected) != 0) {
827 827
                     cli_dbgmsg("cli_scanxar: archived-checksum mismatch.\n");
828 828
                     cksum_fails++;
829 829
                 } else {
... ...
@@ -835,7 +836,7 @@ int cli_scanxar(cli_ctx *ctx)
835 835
             if (e_cksum != NULL) {
836 836
                 if (do_extract_cksum) {
837 837
                     expected = cli_hex2str((char *)e_cksum);
838
-                    if (xar_hash_check(e_hash, result, expected) != 0) {
838
+                    if (xar_hash_check(e_hash, e_hash_result, expected) != 0) {
839 839
                         cli_dbgmsg("cli_scanxar: extracted-checksum mismatch.\n");
840 840
                         cksum_fails++;
841 841
                     } else {
... ...
@@ -871,9 +872,9 @@ int cli_scanxar(cli_ctx *ctx)
871 871
 exit_tmpfile:
872 872
     xar_cleanup_temp_file(ctx, fd, tmpname);
873 873
     if (a_hash_ctx != NULL)
874
-        xar_hash_final(a_hash_ctx, result, a_hash);
874
+        xar_hash_final(a_hash_ctx, a_hash_result, a_hash);
875 875
     if (e_hash_ctx != NULL)
876
-        xar_hash_final(e_hash_ctx, result, e_hash);
876
+        xar_hash_final(e_hash_ctx, e_hash_result, e_hash);
877 877
 
878 878
 exit_reader:
879 879
     if (a_cksum != NULL)