This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Pablo Neira Ayuso gerrit-no-reply at lists.osmocom.orgPablo Neira Ayuso has submitted this change and it was merged.
Change subject: src: _snprintf() helper functions nul-terminate buffers, if possible
......................................................................
src: _snprintf() helper functions nul-terminate buffers, if possible
This patch inconditionally initializes the buffer we get to
nul-terminate it, whenever possible. It's a very simple solution to
catch three overly corner cases:
1) snprintf() returns -1, very much unlikely in practise.
2) msg->len == 0: In such case, I would expect this function is never
   called with an empty message, but let's be safe in this case too.
3) If your buffer is empty, it doesn't nul-terminate the buffer.
Change-Id: I97e517f2d98e83894ea707c63489559302ff6bd2
---
M src/osmux.c
M src/rtp.c
2 files changed, 6 insertions(+), 0 deletions(-)
Approvals:
  Pau Espin Pedrol: Looks good to me, but someone else must approve
  Neels Hofmeyr: Looks good to me, approved
  Jenkins Builder: Verified
diff --git a/src/osmux.c b/src/osmux.c
index b18246f..7290d99 100644
--- a/src/osmux.c
+++ b/src/osmux.c
@@ -902,6 +902,9 @@
 	int msg_len = msg->len;
 	int ret;
 
+	if (size)
+		buf[0] = '\0';
+
 	while (msg_len > 0) {
 		if (msg_len < sizeof(struct osmux_hdr)) {
 			LOGP(DLMIB, LOGL_ERROR,
diff --git a/src/rtp.c b/src/rtp.c
index 56fc37c..48cb9b0 100644
--- a/src/rtp.c
+++ b/src/rtp.c
@@ -200,6 +200,9 @@
 	uint8_t *payload;
 	int ret, i;
 
+	if (size)
+		buf[0] = '\0';
+
 	rtph = osmo_rtp_get_hdr(msg);
 	if (rtph == NULL)
 		return -1;
-- 
To view, visit https://gerrit.osmocom.org/3830
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I97e517f2d98e83894ea707c63489559302ff6bd2
Gerrit-PatchSet: 3
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Pablo Neira Ayuso <pablo at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Pablo Neira Ayuso <pablo at gnumonks.org>
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>