Skip to content

Commit

Permalink
Fix crash on subscribe under certain unlikely conditions.
Browse files Browse the repository at this point in the history
Closes #2885.
Closes #2881.

Thanks to everybody on those issues.
  • Loading branch information
ralight committed Sep 12, 2023
1 parent 1ed275b commit f09ea91
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
8 changes: 8 additions & 0 deletions ChangeLog.txt
@@ -1,3 +1,11 @@
2.0.18 - 2023-09-12
===================

Broker:
- Fix crash on subscribe under certain unlikely conditions. Closes #2885.
Closes #2881.


2.0.17 - 2023-08-22
===================

Expand Down
9 changes: 9 additions & 0 deletions config.mk
Expand Up @@ -120,6 +120,9 @@ WITH_JEMALLOC:=no
# probably of no particular interest to end users.
WITH_XTREPORT=no

# Build using clang and with address sanitiser enabled
WITH_ASAN=no

# =============================================================================
# End of user configuration
# =============================================================================
Expand Down Expand Up @@ -152,6 +155,12 @@ else
CFLAGS?=-Wall -ggdb -O2 -Wconversion -Wextra
endif

ifeq ($(WITH_ASAN),yes)
CC:=clang
CFLAGS+=-fsanitize=address
LDFLAGS+=-fsanitize=address
endif

STATIC_LIB_DEPS:=

APP_CPPFLAGS=$(CPPFLAGS) -I. -I../../ -I../../include -I../../src -I../../lib
Expand Down
2 changes: 0 additions & 2 deletions src/subs.c
Expand Up @@ -389,7 +389,6 @@ static int sub__remove_normal(struct mosquitto *context, struct mosquitto__subhi
if(context->subs[i] && context->subs[i]->hier == subhier){
mosquitto__free(context->subs[i]);
context->subs[i] = NULL;
context->sub_count--;
break;
}
}
Expand Down Expand Up @@ -430,7 +429,6 @@ static int sub__remove_shared(struct mosquitto *context, struct mosquitto__subhi

mosquitto__free(context->subs[i]);
context->subs[i] = NULL;
context->sub_count--;
break;
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/broker/data/REGRESSION.json
@@ -0,0 +1,18 @@
[
{
"group": "REGRESSIONS",
"tests": [
{ "name": "subscribe-unsubscribe-crash part 1", "ver":4, "expect_disconnect":false, "msgs": [
{"type":"send", "payload":"82 26 1234 0009 64 72 61 73 68 2F 31 2F 23 00 0009 65 72 61 73 68 2F 32 2F 23 00 0009 63 72 61 73 68 2F 33 2F 23 00"},
{"type":"recv", "payload":"90 05 1234 00 00 00"},
{"type":"send", "payload":"A2 0D 1234 0009 64 72 61 73 68 2F 31 2F 23"},
{"type":"recv", "payload":"B0 02 1234"}
], "comment": "Must be used with part 2 immediately after",
"comment2": "Requires WITH_ASAN=yes"},
{ "name": "subscribe-unsubscribe-crash part 2", "ver":4, "expect_disconnect":false, "msgs": [
{"type":"send", "payload":"82 0E 1234 0009 63 72 61 73 68 2F 33 2F 23 00"},
{"type":"recv", "payload":"90 03 1234 00"}
], "comment": "https://github.com/eclipse/mosquitto/issues/2885"}
]
}
]

0 comments on commit f09ea91

Please sign in to comment.