aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2021-06-10 13:15:20 +0200
committerpespin <pespin@sysmocom.de>2021-06-15 16:29:44 +0000
commitf5b8ed14a9529f7333310299574a80480e78f332 (patch)
treea0ee0c3c6b6120fea270e78f792ffbed95605e07 /tests
parent68ab9c419399af0f76c73b8506153a7df2ec664d (diff)
ctrl: Pre-calculate required size before allocating msgb
This commit fixes crash when response is more than ~4096 chars. Furthermore, we now allocate only the required memory, not 4096 for all messages, which usually don't require it. Test needs to be adapted since it assumed there was more available space at the end of the msgb. Related: OS#5169 Change-Id: I0b8f370f7b08736207f9efed13a0663b5e482824
Diffstat (limited to 'tests')
-rw-r--r--tests/ctrl/ctrl_test.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/tests/ctrl/ctrl_test.c b/tests/ctrl/ctrl_test.c
index b46e9ac5..01fb9f71 100644
--- a/tests/ctrl/ctrl_test.c
+++ b/tests/ctrl/ctrl_test.c
@@ -117,11 +117,14 @@ static void assert_test(struct ctrl_handle *ctrl, struct ctrl_connection *ccon,
} else {
struct msgb *sent_msg = msgb_dequeue(&ccon->write_queue.msg_queue);
OSMO_ASSERT(sent_msg);
- msgb_put_u8(sent_msg, 0);
- printf("replied: '%s'\n", osmo_escape_str((char*)msgb_l2(sent_msg), -1));
+ char *strbuf = talloc_size(sent_msg, msgb_l2len(sent_msg) + 1);
+ memcpy(strbuf, msgb_l2(sent_msg), msgb_l2len(sent_msg));
+ strbuf[msgb_l2len(sent_msg)] = '\0';
+
+ printf("replied: '%s'\n", osmo_escape_str(strbuf, -1));
OSMO_ASSERT(t->reply_str);
- OSMO_ASSERT(!strcmp(t->reply_str, (char*)msgb_l2(sent_msg)));
+ OSMO_ASSERT(!strcmp(t->reply_str, strbuf));
msgb_free(sent_msg);
}
osmo_wqueue_clear(&ccon->write_queue);