From 20e1990667d60f5e7619dad46eff25bb95597a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Mon, 21 Mar 2005 13:31:33 +0000 Subject: [PATCH] check for overflows git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@14671 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/roken/hex.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/roken/hex.c b/lib/roken/hex.c index 29ed0a082..1f0742b91 100644 --- a/lib/roken/hex.c +++ b/lib/roken/hex.c @@ -60,10 +60,9 @@ hex_encode(const void *data, size_t size, char **str) size_t i; char *p; -#ifdef SIZE_T_MAX - if (size + 1 > SIZE_T_MAX/2) + /* check for overflow */ + if (size * 2 < size) return -1; -#endif p = malloc(size * 2 + 1); if (p == NULL) @@ -88,7 +87,9 @@ hex_decode(const char *str, void *data, size_t len) size_t i; l = strlen(str); - if ((l + 1) / 2 > len) + + /* check for overflow, same as (l+1)/2 but overflow safe */ + if ((l/2) + (l&1) > len) return -1; for (i = 0; i < l / 2; i++)