aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorU+039b <*@0x39b.fr>2016-06-18 18:43:44 +0200
committerNick Mathewson <nickm@torproject.org>2016-06-19 12:34:49 -0400
commit58e6a6aaebc32683f041925351d8a8101c86abda (patch)
tree29887f1d7543fe9cf2ac8625b6e8c4ad2f96a88e
parent81cfd5c9a1af1641d980d5b985810fdd85681fa7 (diff)
downloadtor-58e6a6aaebc32683f041925351d8a8101c86abda.tar.gz
tor-58e6a6aaebc32683f041925351d8a8101c86abda.zip
Fix #19063: Add check in utility macro
-rw-r--r--src/common/util.c3
-rw-r--r--src/test/test_util.c5
2 files changed, 8 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 7217cdc81e..97a7e72763 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1111,6 +1111,9 @@ tor_digest256_is_zero(const char *digest)
/* Were there unexpected unconverted characters? */ \
if (!next && *endptr) \
goto err; \
+ /* Illogical (max, min) inputs? */ \
+ if (max < min) \
+ goto err; \
/* Is r within limits? */ \
if (r < min || r > max) \
goto err; \
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 893fc34792..9086437629 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1501,6 +1501,11 @@ test_util_strmisc(void *arg)
tt_int_op(-50L,OP_EQ, tor_parse_long("-50 plus garbage",10,-100,100,&i,&cp));
tt_int_op(1,OP_EQ, i);
tt_str_op(cp,OP_EQ, " plus garbage");
+ /* Illogical min max */
+ tt_int_op(0L,OP_EQ, tor_parse_long("10",10,50,4,&i,NULL));
+ tt_int_op(0,OP_EQ, i);
+ tt_int_op(0L,OP_EQ, tor_parse_long("-50",10,100,-100,&i,NULL));
+ tt_int_op(0,OP_EQ, i);
/* Out of bounds */
tt_int_op(0L,OP_EQ, tor_parse_long("10",10,50,100,&i,NULL));
tt_int_op(0,OP_EQ, i);