]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: fix -a crc on 64 bit big endian systems
authorPádraig Brady <P@draigBrady.com>
Thu, 23 Sep 2021 21:45:53 +0000 (22:45 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 23 Sep 2021 23:39:05 +0000 (00:39 +0100)
* src/cksum.c (crc_sum_stream): On sparc64 for example,
a crc of 0 was printed due to mismatch in size of
variable copied between generator and output functions.
uint_fast32_t is generally 64 bits on 64 bit systems,
so we copy through an int to ensure we don't use the wrong
end of a 64 bit variable.
Reported by Nelson H. F. Beebe

src/cksum.c

index 116d23f8009ae32331ee148f3d3d2bc53f6a2339..51afe89f6828dd4d4f9d89a588ae89e88d6b1644 100644 (file)
@@ -275,7 +275,8 @@ crc_sum_stream (FILE *stream, void *resstream, uintmax_t *length)
     crc = (crc << 8) ^ crctab[0][((crc >> 24) ^ total_bytes) & 0xFF];
   crc = ~crc & 0xFFFFFFFF;
 
-  memcpy (resstream, &crc, sizeof crc);
+  unsigned int crc_out = crc;
+  memcpy (resstream, &crc_out, sizeof crc_out);
 
   return 0;
 }