[PATCH 5/5] logging: make sure the output is null-terminated

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/OpenBSC@lists.osmocom.org/.

pablo at gnumonks.org pablo at gnumonks.org
Tue May 3 20:40:44 UTC 2011


From: Pablo Neira Ayuso <pablo at gnumonks.org>

If we reach the buffer size or snprintf fails, we want to make sure
that the output is null-terminated.
---
 src/logging.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/src/logging.c b/src/logging.c
index 6797afc..0911010 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -493,6 +493,7 @@ const char *log_vty_command_string(const struct log_info *info)
 		goto err;
 	OSMO_SNPRINTF_RET(ret, rem, offset, len);
 err:
+	str[size-1] = '\0';
 	return str;
 }
 
@@ -544,6 +545,7 @@ const char *log_vty_command_description(const struct log_info *info)
 		OSMO_SNPRINTF_RET(ret, rem, offset, len);
 	}
 err:
+	str[size-1] = '\0';
 	return str;
 }
 
-- 
1.7.2.3





More information about the OpenBSC mailing list