summaryrefslogtreecommitdiff
path: root/sys/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2021-07-22 16:40:21 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2021-07-22 16:40:21 +0000
commit4de38fb7709443431ca96b66a271c8e21e4c3d9c (patch)
tree922516e814481da58343fa90eb1c1fd6aebe47b0 /sys/lib
parent001d1cc9f88dbf1cebc88e114f13517f39462ee9 (diff)
Add sizes for free() in zlib
Rebased version of a diff from miod who described it as follows: This tries to keep diffability against upstream, hence a questionable choice of the size type for zcfree() - but all sizes should fit in 32 bits anyway. Since all zcfree routines used in the tree cope with NULL arguments (including the various alloc.c used by the boot blocks), I have simplified TRY_FREE to compensate for the growth. Reminded by and ok mpi
Diffstat (limited to 'sys/lib')
-rw-r--r--sys/lib/libz/deflate.c12
-rw-r--r--sys/lib/libz/infback.c4
-rw-r--r--sys/lib/libz/inflate.c12
-rw-r--r--sys/lib/libz/zlib.h4
-rw-r--r--sys/lib/libz/zopenbsd.c6
-rw-r--r--sys/lib/libz/zutil.h9
6 files changed, 24 insertions, 23 deletions
diff --git a/sys/lib/libz/deflate.c b/sys/lib/libz/deflate.c
index 3247dd91975..5c42b69ea5c 100644
--- a/sys/lib/libz/deflate.c
+++ b/sys/lib/libz/deflate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: deflate.c,v 1.4 2021/07/04 14:24:49 tb Exp $ */
+/* $OpenBSD: deflate.c,v 1.5 2021/07/22 16:40:20 tb Exp $ */
/* deflate.c -- compress data using the deflation algorithm
* Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
@@ -1080,12 +1080,12 @@ int ZEXPORT deflateEnd (strm)
status = strm->state->status;
/* Deallocate in reverse order of allocations: */
- TRY_FREE(strm, strm->state->pending_buf);
- TRY_FREE(strm, strm->state->head);
- TRY_FREE(strm, strm->state->prev);
- TRY_FREE(strm, strm->state->window);
+ TRY_FREE(strm, strm->state->pending_buf, strm->state->pending_buf_size);
+ TRY_FREE(strm, strm->state->head, strm->state->hash_size * sizeof(Pos));
+ TRY_FREE(strm, strm->state->prev, strm->state->w_size * sizeof(Pos));
+ TRY_FREE(strm, strm->state->window, strm->state->w_size * 2 * sizeof(Pos));
- ZFREE(strm, strm->state);
+ ZFREE(strm, strm->state, sizeof(deflate_state));
strm->state = Z_NULL;
return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
diff --git a/sys/lib/libz/infback.c b/sys/lib/libz/infback.c
index 037ecac581c..d411c530020 100644
--- a/sys/lib/libz/infback.c
+++ b/sys/lib/libz/infback.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: infback.c,v 1.7 2021/07/04 14:24:49 tb Exp $ */
+/* $OpenBSD: infback.c,v 1.8 2021/07/22 16:40:20 tb Exp $ */
/* infback.c -- inflate using a call-back interface
* Copyright (C) 1995-2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
@@ -684,7 +684,7 @@ z_streamp strm;
{
if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
return Z_STREAM_ERROR;
- ZFREE(strm, strm->state);
+ ZFREE(strm, strm->state, sizeof(struct inflate_state));
strm->state = Z_NULL;
Tracev((stderr, "inflate: end\n"));
return Z_OK;
diff --git a/sys/lib/libz/inflate.c b/sys/lib/libz/inflate.c
index 5e3d8ef2169..a28ffece737 100644
--- a/sys/lib/libz/inflate.c
+++ b/sys/lib/libz/inflate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inflate.c,v 1.16 2021/07/04 14:24:49 tb Exp $ */
+/* $OpenBSD: inflate.c,v 1.17 2021/07/22 16:40:20 tb Exp $ */
/* inflate.c -- zlib decompression
* Copyright (C) 1995-2016 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
@@ -183,7 +183,7 @@ int windowBits;
if (windowBits && (windowBits < 8 || windowBits > 15))
return Z_STREAM_ERROR;
if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) {
- ZFREE(strm, state->window);
+ ZFREE(strm, state->window, 1U << state->wbits);
state->window = Z_NULL;
}
@@ -231,7 +231,7 @@ int stream_size;
state->mode = HEAD; /* to pass state test in inflateReset2() */
ret = inflateReset2(strm, windowBits);
if (ret != Z_OK) {
- ZFREE(strm, state);
+ ZFREE(strm, state, sizeof(struct inflate_state));
strm->state = Z_NULL;
}
return ret;
@@ -1368,8 +1368,8 @@ z_streamp strm;
if (inflateStateCheck(strm))
return Z_STREAM_ERROR;
state = (struct inflate_state FAR *)strm->state;
- if (state->window != Z_NULL) ZFREE(strm, state->window);
- ZFREE(strm, strm->state);
+ if (state->window != Z_NULL) ZFREE(strm, state->window, 1U << state->wbits);
+ ZFREE(strm, strm->state, sizeof(struct inflate_state));
strm->state = Z_NULL;
Tracev((stderr, "inflate: end\n"));
return Z_OK;
@@ -1568,7 +1568,7 @@ z_streamp source;
window = (unsigned char FAR *)
ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
if (window == Z_NULL) {
- ZFREE(source, copy);
+ ZFREE(source, copy, sizeof(struct inflate_state));
return Z_MEM_ERROR;
}
}
diff --git a/sys/lib/libz/zlib.h b/sys/lib/libz/zlib.h
index e2d1d347361..2a6df8fae91 100644
--- a/sys/lib/libz/zlib.h
+++ b/sys/lib/libz/zlib.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: zlib.h,v 1.13 2021/07/04 17:41:23 tb Exp $ */
+/* $OpenBSD: zlib.h,v 1.14 2021/07/22 16:40:20 tb Exp $ */
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.2.11, January 15th, 2017
@@ -81,7 +81,7 @@ extern "C" {
*/
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
-typedef void (*free_func) OF((voidpf opaque, voidpf address));
+typedef void (*free_func) OF((voidpf opaque, voidpf address, uInt size));
struct internal_state;
diff --git a/sys/lib/libz/zopenbsd.c b/sys/lib/libz/zopenbsd.c
index 3842b199a29..1a45452e268 100644
--- a/sys/lib/libz/zopenbsd.c
+++ b/sys/lib/libz/zopenbsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: zopenbsd.c,v 1.9 2021/07/04 17:51:20 deraadt Exp $ */
+/* $OpenBSD: zopenbsd.c,v 1.10 2021/07/22 16:40:20 tb Exp $ */
/*
* Copyright (c) 2011 Theo de Raadt <deraadt@openbsd.org>
@@ -29,7 +29,7 @@ zcalloc(void *notused, u_int items, u_int size)
}
void
-zcfree(void *notused, void *ptr)
+zcfree(void *notused, void *ptr, u_int size)
{
- free(ptr, M_DEVBUF, 0);
+ free(ptr, M_DEVBUF, size);
}
diff --git a/sys/lib/libz/zutil.h b/sys/lib/libz/zutil.h
index 061234b12aa..16bfb16db0e 100644
--- a/sys/lib/libz/zutil.h
+++ b/sys/lib/libz/zutil.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: zutil.h,v 1.21 2021/07/08 20:02:42 deraadt Exp $ */
+/* $OpenBSD: zutil.h,v 1.22 2021/07/22 16:40:20 tb Exp $ */
/* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler
@@ -270,13 +270,14 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
#ifndef Z_SOLO
voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
unsigned size));
- void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
+ void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr, unsigned size));
#endif
#define ZALLOC(strm, items, size) \
(*((strm)->zalloc))((strm)->opaque, (items), (size))
-#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
-#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
+#define ZFREE(strm, addr, size) \
+ (*((strm)->zfree))((strm)->opaque, (voidpf)(addr), (size))
+#define TRY_FREE(s, p, size) ZFREE(s, p, size)
/* Reverse the bytes in a 32-bit value */
#define ZSWAP32(q) ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \