diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-12-02 04:33:01 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-12-02 04:33:01 +0000 |
commit | a980446d0cf8f455c49f6543bd8486b442e326b1 (patch) | |
tree | 2a575e8d2b88971d850174fbe35de613142508d5 /src/common/util.c | |
parent | db5e100cde18bfb5d35c409f0fbb62e8e7438c38 (diff) | |
download | tor-a980446d0cf8f455c49f6543bd8486b442e326b1.tar.gz tor-a980446d0cf8f455c49f6543bd8486b442e326b1.zip |
Be more proactive about noticing underflows: size_t values greater than 0x800...00 are likely to be trouble.
svn:r3064
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c index 169dbf14bd..dd6ff289ee 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -18,6 +18,7 @@ const char util_c_id[] = "$Id$"; #include "util.h" #include "log.h" #include "crypto.h" +#include "torint.h" #ifdef MS_WINDOWS #include <io.h> @@ -218,6 +219,8 @@ int tor_strpartition(char *dest, size_t dest_len, tor_assert(s); tor_assert(insert); tor_assert(n > 0); + tor_assert(n < SIZE_T_CEILING); + tor_assert(dest_len < SIZE_T_CEILING); len_in = strlen(s); len_ins = strlen(insert); len_out = len_in + (len_in/n)*len_ins; @@ -444,6 +447,7 @@ void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen) char *cp; tor_assert(destlen >= srclen*2+1); + tor_assert(destlen < SIZE_T_CEILING); cp = dest; end = src+srclen; @@ -477,7 +481,7 @@ int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen) int v1,v2; if ((srclen % 2) != 0) return -1; - if (destlen < srclen/2) + if (destlen < srclen/2 || destlen > SIZE_T_CEILING) return -1; end = src+srclen; while (src<end) { @@ -703,6 +707,9 @@ int read_all(int fd, char *buf, size_t count, int isSocket) { size_t numread = 0; int result; + if (count > SIZE_T_CEILING) + return -1; + while (numread != count) { if (isSocket) result = recv(fd, buf+numread, count-numread, 0); |