summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-03-30 10:34:05 -0400
committerNick Mathewson <nickm@torproject.org>2012-03-30 10:34:05 -0400
commit56e0959d2ab9cae45d39c5b9d72b1bb1b8ad03b7 (patch)
treeac7c4cb7ece2df9fea2307f8690741c939e00559
parent88caa552cc3742189124c297e7cf65ac5e5ef332 (diff)
downloadtor-56e0959d2ab9cae45d39c5b9d72b1bb1b8ad03b7.tar.gz
tor-56e0959d2ab9cae45d39c5b9d72b1bb1b8ad03b7.zip
Have tor_parse_*long functions check for negative bases
One of our unit tests checks that they behave correctly (giving an error) when the base is negative. But there isn't a guarantee that strtol and friends actually handle negative bases correctly. Found by Coverity Scan; fix for CID 504.
-rw-r--r--src/common/util.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 1807ee7adc..266368cc9d 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -906,6 +906,11 @@ tor_parse_long(const char *s, int base, long min, long max,
char *endptr;
long r;
+ if (base < 0) {
+ if (ok)
+ *ok = 0;
+ return 0;
+ }
r = strtol(s, &endptr, base);
CHECK_STRTOX_RESULT();
}
@@ -918,6 +923,11 @@ tor_parse_ulong(const char *s, int base, unsigned long min,
char *endptr;
unsigned long r;
+ if (base < 0) {
+ if (ok)
+ *ok = 0;
+ return 0;
+ }
r = strtoul(s, &endptr, base);
CHECK_STRTOX_RESULT();
}
@@ -942,6 +952,12 @@ tor_parse_uint64(const char *s, int base, uint64_t min,
char *endptr;
uint64_t r;
+ if (base < 0) {
+ if (ok)
+ *ok = 0;
+ return 0;
+ }
+
#ifdef HAVE_STRTOULL
r = (uint64_t)strtoull(s, &endptr, base);
#elif defined(_WIN32)