diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-05-02 19:14:31 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-05-02 19:43:05 (EDT) |
commit | 17db76f6ba811b102935bd8796188996c89db860 (patch) | |
tree | 7cf14aa64703caf9b9e671ebba1a18555438086c | |
parent | d1383915089af484e68ae5ce03f5c20e78ad0726 (diff) |
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.
-rw-r--r-- | src/gzip.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -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; |