Review at https://gerrit.osmocom.org/3830
src: _snprintf() helper functions always nul-terminate buffers
Add the \0 for every case, even if this does not match exactly the
snprintf semantics.
Change-Id: I97e517f2d98e83894ea707c63489559302ff6bd2
---
M src/osmux.c
M src/rtp.c
2 files changed, 15 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/30/3830/1
diff --git a/src/osmux.c b/src/osmux.c
index b18246f..683c6e9 100644
--- a/src/osmux.c
+++ b/src/osmux.c
@@ -938,6 +938,13 @@
msg_len -= this_len;
}
+ /* This _snprintf() variant always nul-terminates the buffer. */
+ if (!offset)
+ buf[0] = '\0';
+ else if (offset + 1 >= size)
+ buf[offset] = '\0';
+ else
+ buf[++offset] = '\0';
return offset;
}
diff --git a/src/rtp.c b/src/rtp.c
index 56fc37c..f524f73 100644
--- a/src/rtp.c
+++ b/src/rtp.c
@@ -223,5 +223,13 @@
ret = snprintf(buf + offset, remain, "]");
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+ /* This _snprintf() variant always nul-terminates the buffer. */
+ if (!offset)
+ buf[0] = '\0';
+ else if (offset + 1 >= size)
+ buf[offset] = '\0';
+ else
+ buf[++offset] = '\0';
+
return offset;
}
--
To view, visit https://gerrit.osmocom.org/3830
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I97e517f2d98e83894ea707c63489559302ff6bd2
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Pablo Neira Ayuso <[email protected]>