Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sys/net/application_layer/emcute/emcute.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ int emcute_con(sock_udp_ep_t *remote, bool clean, const char *will_topic,

/* check for existing connections and copy given UDP endpoint */
if (gateway.port != 0) {
mutex_unlock(&txlock);
return EMCUTE_NOGW;
}
memcpy(&gateway, remote, sizeof(sock_udp_ep_t));
Expand All @@ -249,12 +250,14 @@ int emcute_con(sock_udp_ep_t *remote, bool clean, const char *will_topic,
if ((topic_len > CONFIG_EMCUTE_TOPIC_MAXLEN) ||
((will_msg_len + 4) > CONFIG_EMCUTE_BUFSIZE)) {
gateway.port = 0;
mutex_unlock(&txlock);
return EMCUTE_OVERFLOW;
}

res = syncsend(WILLTOPICREQ, len, false);
if (res != EMCUTE_OK) {
gateway.port = 0;
mutex_unlock(&txlock);
return res;
}

Expand All @@ -268,6 +271,7 @@ int emcute_con(sock_udp_ep_t *remote, bool clean, const char *will_topic,
res = syncsend(WILLMSGREQ, len, false);
if (res != EMCUTE_OK) {
gateway.port = 0;
mutex_unlock(&txlock);
return res;
}

Expand Down
14 changes: 13 additions & 1 deletion tests/net/emcute/tests-as-root/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
MODES = set(["pub", "sub", "sub_w_reg"])
INTER_PACKET_GAP = 0.07
TIMEOUT = 1
TOPIC_MAX_LEN = 249


class MQTTSNServer(Automaton):
Expand Down Expand Up @@ -456,13 +457,24 @@ def get_host_lladdr(tap):
return res


def check_will_topic_overflow_releases_txlock(child, gw_addr):
utils.test_utils_interactive_sync_shell(child,
TEST_INTERACTIVE_RETRIES,
TEST_INTERACTIVE_DELAY)
will_topic = "/" + ("x" * TOPIC_MAX_LEN)
for _ in range(2):
child.sendline("con {} {} msg".format(gw_addr, will_topic))
child.expect_exact("error: unable to connect to {}".format(gw_addr))


def testfunc(child):
tap = get_bridge(os.environ["TAP"])
lladdr = get_host_lladdr(tap)
gw_addr = "[{}%{}]:{}".format(lladdr, tap, SERVER_PORT)

time.sleep(1)
DATA_MAX_LEN = 512 - 9 # PUBLISH + 2 byte extra for length
TOPIC_MAX_LEN = 249 # see Makefile
check_will_topic_overflow_releases_txlock(child, gw_addr)
for test_params in [
{"qos_level": 0, "mode": "sub", "topic_name": "/test",
"data_len_start": 0, "data_len_end": DATA_MAX_LEN,
Expand Down