aboutsummaryrefslogtreecommitdiffstats
path: root/tests/osmux
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@gnumonks.org>2017-09-04 20:35:36 +0200
committerHarald Welte <laforge@gnumonks.org>2017-09-11 18:06:37 +0000
commit14af167a5553519d8164f4a21556888535eeefeb (patch)
treef851eb5db131ed26c4fabcc57bdff06d226965b5 /tests/osmux
parent9c5f01e7b2cb1455314443ceaeb035326354d280 (diff)
osmux: fix buffer management mess in snprintf() calls
SNPRINTF_BUFFER_SIZE() looks too complex, previous version maintains two different variables to account for the remaining space in the buffer, one of them is always decremented based on what snprintf() returns, which may result in underflow. These variables are swapped - not used consistently - all over this code. Replace this macro by a simplified version, with one single parameter to account for remaining space. This macro also deals with two corner cases: 1) snprintf() fails, actually never happens in practise, but documentation indicates it may return -1, so let's catch this case from here to stick to specs. 2) There is not enough space in the buffer, in that case, keep increasing offset, so we know how much would have been printed, just like snprintf() does. Thanks to Pau Espin for reporting, and Holger for clues on this. I have run osmux_test and, at quick glance, it looks good. Change-Id: I5b5d6ec57a02f57c23b1ae86dbd894bad28ea797
Diffstat (limited to 'tests/osmux')
-rw-r--r--tests/osmux/osmux_test.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/tests/osmux/osmux_test.c b/tests/osmux/osmux_test.c
index bf6174b..09b7a9a 100644
--- a/tests/osmux/osmux_test.c
+++ b/tests/osmux/osmux_test.c
@@ -65,8 +65,8 @@ static struct timeval last;
static void tx_cb(struct msgb *msg, void *data)
{
- char buf[4096];
struct rtp_hdr *rtph = (struct rtp_hdr *)msg->data;
+ char buf[4096];
#if OSMUX_TEST_USE_TIMING
struct timeval now, diff;
@@ -102,9 +102,9 @@ static struct osmux_out_handle h_output;
static void osmux_deliver(struct msgb *batch_msg, void *data)
{
- char buf[2048];
struct osmux_hdr *osmuxh;
LLIST_HEAD(list);
+ char buf[2048];
osmux_snprintf(buf, sizeof(buf), batch_msg);
fprintf(stderr, "OSMUX message (len=%d) %s\n", batch_msg->len, buf);
@@ -182,11 +182,11 @@ static void osmux_test_marker(int ccid) {
static void osmux_test_loop(int ccid)
{
+ struct rtp_hdr *rtph = (struct rtp_hdr *)rtp_pkt;
struct msgb *msg;
+ int i, j, k = 0;
char buf[1024];
- struct rtp_hdr *rtph = (struct rtp_hdr *)rtp_pkt;
uint16_t seq;
- int i, j, k = 0;
for (i = 1; i < 65; i++) {
msg = msgb_alloc(1500, "test");