summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/compat.c8
-rw-r--r--src/test/test_addr.c9
2 files changed, 15 insertions, 2 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 23eaa134cf..ede850792f 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -2610,8 +2610,12 @@ tor_inet_pton(int af, const char *src, void *dst)
char *next;
ssize_t len;
long r = strtol(src, &next, 16);
- tor_assert(next != NULL);
- tor_assert(next != src);
+ if (next == NULL || next == src) {
+ /* The 'next == src' error case can happen on versions of openbsd
+ * where treats "0xfoo" as an error, rather than as "0" followed by
+ * "xfoo". */
+ return 0;
+ }
len = *next == '\0' ? eow - src : next - src;
if (len > 4)
diff --git a/src/test/test_addr.c b/src/test/test_addr.c
index 337bddad6b..56e79d707a 100644
--- a/src/test/test_addr.c
+++ b/src/test/test_addr.c
@@ -354,6 +354,15 @@ test_addr_ip6_helpers(void *arg)
test_pton6_bad("1.2.3.4");
test_pton6_bad(":1.2.3.4");
test_pton6_bad(".2.3.4");
+ /* Regression tests for 22789. */
+ test_pton6_bad("0xfoo");
+ test_pton6_bad("0x88");
+ test_pton6_bad("0xyxxy");
+ test_pton6_bad("0XFOO");
+ test_pton6_bad("0X88");
+ test_pton6_bad("0XYXXY");
+ test_pton6_bad("0x");
+ test_pton6_bad("0X");
/* test internal checking */
test_external_ip("fbff:ffff::2:7", 0);