[MERGED] libosmocore[master]: vty/command.c: write_config_file(): sanely compose temp path

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/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Wed Mar 28 18:54:19 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: vty/command.c: write_config_file(): sanely compose temp path
......................................................................


vty/command.c: write_config_file(): sanely compose temp path

Fix GCC version 7.3.0 (Debian 7.3.0-12) compiler warning:

../../../../src/libosmocore/src/vty/command.c: In function ‘write_config_file’:
../../../../src/libosmocore/src/vty/command.c:2741:2: error: null destination pointer [-Werror=format-overflow=]
  sprintf(config_file_tmp, "%s.XXXXXX", config_file);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check agains NULL after each _talloc_zero() in write_config_file().

While at it, add a comment explaining why we don't use talloc_asprintf() instead.

Change-Id: I7bdc52afe724c1d21f419fe49a6e2ebca9420969
---
M src/vty/command.c
1 file changed, 11 insertions(+), 1 deletion(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/vty/command.c b/src/vty/command.c
index 71f6a71..24d8ea4 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -2728,16 +2728,26 @@
 
 	*outpath = NULL;
 
+	/* The string composition code here would be a case for talloc_asprintf(), but the pseudotalloc.c
+	 * talloc_asprintf() implementation would truncate a too-long path with "[...]", so doing it
+	 * manually instead. */
+
 	/* Check and see if we are operating under vtysh configuration */
 	config_file_sav =
 	    _talloc_zero(tall_vty_cmd_ctx,
 			 strlen(config_file) + strlen(CONF_BACKUP_EXT) + 1,
 			 "config_file_sav");
+	if (!config_file_sav)
+		return -1;
 	strcpy(config_file_sav, config_file);
 	strcat(config_file_sav, CONF_BACKUP_EXT);
 
 	config_file_tmp = _talloc_zero(tall_vty_cmd_ctx, strlen(config_file) + 8,
-					"config_file_tmp");
+				       "config_file_tmp");
+	if (!config_file_tmp) {
+		talloc_free(config_file_sav);
+		return -1;
+	}
 	sprintf(config_file_tmp, "%s.XXXXXX", config_file);
 
 	/* Open file to configuration write. */

-- 
To view, visit https://gerrit.osmocom.org/7554
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7bdc52afe724c1d21f419fe49a6e2ebca9420969
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list