summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-10-01 12:55:42 -0400
committerNick Mathewson <nickm@torproject.org>2019-10-01 13:01:20 -0400
commit2b825a1a2e6e79fa71b0e038241d2107aaf30d4b (patch)
treeee760f1c28eb252393c5129b4d9f93fefc014aab
parent34bbdaf5d4673491216b64f5ab983518b3f8c7d1 (diff)
downloadtor-2b825a1a2e6e79fa71b0e038241d2107aaf30d4b.tar.gz
tor-2b825a1a2e6e79fa71b0e038241d2107aaf30d4b.zip
Fix a crash bug in max_u16_in_sl()
The documentation for this function says that the smartlist can contain NULLs, but the code only handled NULLs if they were at the start of the list. We didn't notice this for a long time, because when Tor is run normally, the sequence of msg_id_t is densely packed, and so this list (mapping msg_id_t to channel_id_t) contains no NULL elements. We could only run into this bug: * when Tor was running in embedded mode, and starting more than once. * when Tor ran first with more pubsub messages enabled, and then later with fewer. * When the second run (the one with fewer enabled pubsub messages) had at least some messages enabled, and those messages were not the ones with numerically highest msg_id_t values. Fixes bug 31898; bugfix on 47de9c7b0a828de7fb8129413db70bc4e4ecac6d in 0.4.1.1-alpha.
-rw-r--r--changes/bug318984
-rw-r--r--src/lib/dispatch/dispatch_new.c2
2 files changed, 5 insertions, 1 deletions
diff --git a/changes/bug31898 b/changes/bug31898
new file mode 100644
index 0000000000..6f3e0a5465
--- /dev/null
+++ b/changes/bug31898
@@ -0,0 +1,4 @@
+ o Major bugfixes (embedded Tor):
+ - Avoid a possible crash when restarting Tor in embedded mode and
+ enabling a different set of publish/subscribe messages. Fixes bug
+ 31898; bugfix on 0.4.1.1-alpha.
diff --git a/src/lib/dispatch/dispatch_new.c b/src/lib/dispatch/dispatch_new.c
index 4467813064..d8e59d610a 100644
--- a/src/lib/dispatch/dispatch_new.c
+++ b/src/lib/dispatch/dispatch_new.c
@@ -34,7 +34,7 @@ max_in_u16_sl(const smartlist_t *sl, int dflt)
SMARTLIST_FOREACH_BEGIN(sl, uint16_t *, u) {
if (!maxptr)
maxptr = u;
- else if (*u > *maxptr)
+ else if (u && *u > *maxptr)
maxptr = u;
} SMARTLIST_FOREACH_END(u);