From 17db76f6ba811b102935bd8796188996c89db860 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 02 May 2023 19:14:31 -0400 Subject: gzip: Preserve gzip header zlib doesn't copy it anywhere between deflateSetHeader() and deflate(), so we need to make sure it doesn't get corrupted on the stack in the meantime. --- diff --git a/src/gzip.c b/src/gzip.c index fbd40ef..736cbd7 100644 --- a/src/gzip.c +++ b/src/gzip.c @@ -38,6 +38,7 @@ struct opkg_opk_gzip { opkg_opk_gzip_write_func *write_func; void *user_data; z_stream stream; + gz_header gz_header; }; static struct opkg_opk_gzip * @@ -46,7 +47,6 @@ _opkg_opk_gzip_init(enum _opkg_opk_gzip_dir dir, opkg_opk_gzip_write_func *write_func, void *user_data) { struct opkg_opk_gzip *gzip; - gz_header gz_header; gzip = malloc(sizeof(*gzip)); if (gzip == NULL) { @@ -79,14 +79,14 @@ _opkg_opk_gzip_init(enum _opkg_opk_gzip_dir dir, free(gzip); return NULL; } - gz_header.text = 0; - gz_header.time = 0; /* Stored as 32-bit unsigned int */ - gz_header.os = 3; /* Unix, per RFC 1952 */ - gz_header.extra = Z_NULL; - gz_header.name = Z_NULL; - gz_header.comment = Z_NULL; - gz_header.hcrc = 0; - if (deflateSetHeader(&gzip->stream, &gz_header) != Z_OK) { + gzip->gz_header.text = 0; + gzip->gz_header.time = 0; /* Stored as 32-bit uint */ + gzip->gz_header.os = 3; /* Unix, per RFC 1952 */ + gzip->gz_header.extra = Z_NULL; + gzip->gz_header.name = Z_NULL; + gzip->gz_header.comment = Z_NULL; + gzip->gz_header.hcrc = 0; + if (deflateSetHeader(&gzip->stream, &gzip->gz_header) != Z_OK) { deflateEnd(&gzip->stream); free(gzip); return NULL; -- cgit v0.9.1