Change in libosmocore[master]: osmo-config-merge: Fix some small issues

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
Fri Sep 28 22:59:22 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/11132 )

Change subject: osmo-config-merge: Fix some small issues
......................................................................

osmo-config-merge: Fix some small issues

Allocate NULL context after exit_usage() calls and free it before exit
so * sanitizer is happy.
Also handle the error cases gracefully when a file is unreadable or
formatted wrong.

Change-Id: I966e63a3f7d0ff71ee0b88922aa3807d073aa232
---
M utils/osmo-config-merge.c
1 file changed, 15 insertions(+), 4 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Vadim Yanitskiy: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved



diff --git a/utils/osmo-config-merge.c b/utils/osmo-config-merge.c
index c76e42d..a872d64 100644
--- a/utils/osmo-config-merge.c
+++ b/utils/osmo-config-merge.c
@@ -44,6 +44,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 
 #include <osmocom/core/linuxlist.h>
 #include <osmocom/core/talloc.h>
@@ -126,8 +127,11 @@
 	unsigned int line_num = 0;
 
 	infile = fopen(fname, "r");
-	if (!infile)
+	if (!infile) {
+		fprintf(stderr, "Could not open file '%s': %s\n",
+			fname, strerror(errno));
 		return NULL;
+	}
 
 	root = node_alloc(ctx);
 	last = root;
@@ -140,7 +144,7 @@
 			if (indent > cur_indent+1) {
 				fprintf(stderr, "File '%s' isn't well-formed in line %u, aborting!\n",
 					fname, line_num);
-				exit(2);
+				return NULL;
 			}
 			/* new child to last node */
 			n = node_alloc_child(last);
@@ -229,8 +233,7 @@
 	const char *base_fname, *patch_fname;
 	struct node *base_tree, *patch_tree;
 	bool debug_enabled = false;
-
-	void *ctx = talloc_named_const(NULL, 0, "root");
+	void *ctx;
 
 	if (argc < 3)
 		exit_usage(1);
@@ -245,9 +248,16 @@
 			exit_usage(1);
 	}
 
+	ctx = talloc_named_const(NULL, 0, "root");
+
 	base_tree = file_read(ctx, base_fname);
 	patch_tree = file_read(ctx, patch_fname);
 
+	if (!base_tree || ! patch_tree) {
+		talloc_free(ctx);
+		return 2;
+	}
+
 	if (debug_enabled) {
 		fprintf(stderr, "====== dumping tree (base)\n");
 		dump_node(base_tree, stderr, true);
@@ -265,6 +275,7 @@
 	/* make AddressSanitizer / LeakSanitizer happy by recursively freeing the trees */
 	talloc_free(patch_tree);
 	talloc_free(base_tree);
+	talloc_free(ctx);
 
 	return 0;
 }

-- 
To view, visit https://gerrit.osmocom.org/11132
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I966e63a3f7d0ff71ee0b88922aa3807d073aa232
Gerrit-Change-Number: 11132
Gerrit-PatchSet: 4
Gerrit-Owner: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180928/85a00099/attachment.htm>


More information about the gerrit-log mailing list