commit 5211b8c8bd321f8277cc2a08b18cc72e5259f87f from: Stefan Sperling date: Tue Mar 19 12:26:23 2019 UTC improve error checking around inflateInit() commit - 23bc48a9950c0704e7698686e89a6980c23529f4 commit + 5211b8c8bd321f8277cc2a08b18cc72e5259f87f blob - 28506a878c1f7f6d390a31f3b9960addcd1a3470 blob + d5a41ac80b86adcdf3016cddcccfd30b3f49a3ce --- lib/inflate.c +++ lib/inflate.c @@ -16,6 +16,7 @@ #include +#include #include #include #include @@ -37,14 +38,21 @@ const struct got_error * got_inflate_init(struct got_inflate_buf *zb, uint8_t *outbuf, size_t bufsize) { const struct got_error *err = NULL; + int zerr; memset(&zb->z, 0, sizeof(zb->z)); zb->z.zalloc = Z_NULL; zb->z.zfree = Z_NULL; - if (inflateInit(&zb->z) != Z_OK) { - err = got_error(GOT_ERR_IO); - goto done; + zerr = inflateInit(&zb->z); + if (zerr != Z_OK) { + if (zerr == Z_ERRNO) + return got_error_from_errno(); + if (zerr == Z_MEM_ERROR) { + errno = ENOMEM; + return got_error_from_errno(); + } + return got_error(GOT_ERR_DECOMPRESSION); } zb->inlen = zb->outlen = bufsize;