Fix gzip compressed core dumps on big endian architectures

The gzip trailer words (size and CRC) are both little-endian per the spec.

MFC after:	3 days
Sponsored by:	Juniper Networks, Inc.
This commit is contained in:
Justin Hibbits 2022-02-10 09:21:36 -06:00
parent b51927b7b0
commit 6db44b0158

View File

@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h>
#include <sys/compressor.h>
#include <sys/endian.h>
#include <sys/kernel.h>
#include <sys/linker_set.h>
#include <sys/malloc.h>
@ -201,9 +202,9 @@ gz_write(void *stream, void *data, size_t len, compressor_cb_t cb,
* Try to pack as much of the trailer into the
* output buffer as we can.
*/
((uint32_t *)trailer)[0] = s->gz_crc;
((uint32_t *)trailer)[0] = htole32(s->gz_crc);
((uint32_t *)trailer)[1] =
s->gz_stream.total_in;
htole32(s->gz_stream.total_in);
room = MIN(sizeof(trailer),
s->gz_bufsz - len);
memcpy(s->gz_buffer + len, trailer, room);