[PATCH] osmo-ggsn[master]: sgsnemu: Don't leak FILE handle in proc_read()

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
Sun Nov 5 17:45:19 UTC 2017


Review at  https://gerrit.osmocom.org/4682

sgsnemu: Don't leak FILE handle in proc_read()

Change-Id: Ie22e6a9bc172427e867e7a4001b6c710477a232b
Fixes: Coverity CID#178660
---
M ggsn/gtp-kernel.c
M sgsnemu/sgsnemu.c
2 files changed, 10 insertions(+), 35 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-ggsn refs/changes/82/4682/1

diff --git a/ggsn/gtp-kernel.c b/ggsn/gtp-kernel.c
index f98586d..916b92f 100644
--- a/ggsn/gtp-kernel.c
+++ b/ggsn/gtp-kernel.c
@@ -11,6 +11,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <inttypes.h>
 #include <sys/types.h>
 #include <arpa/inet.h>
 #include <net/if.h>
@@ -36,37 +37,15 @@
 
 static void pdp_debug(struct pdp_t *pdp)
 {
-	int i;
-	uint64_t teid;
+	struct in46_addr ia46;
+	struct in_addr ia;
 
-	if (!debug)
-		return;
+	in46a_from_eua(&pdp->eua, &ia46);
+	gsna2in_addr(&ia, &pdp->gsnrc);
 
-	printf("version %u\n", pdp->version);
-	if (pdp->version == 0) {
-		teid = pdp_gettid(pdp->imsi, pdp->nsapi);
-		printf("flowid %u\n", pdp->flru);
-	} else {
-		teid = pdp->teid_gn; /* GTPIE_TEI_DI */
-	}
-
-	printf("teid %llx\n", teid);
-	printf("address (%u)\n", pdp->eua.l);
-
-	/* Byte 0: 0xf1 == IETF */
-	/* Byte 1: 0x21 == IPv4 */
-	/* Byte 2-6: IPv4 address */
-
-	for (i = 0; i < 6; i++)
-		printf("%x ", pdp->eua.v[i] & 0xff); /* GTPIE_EUA */
-
-	printf("\n");
-	printf("sgsn-addr (%u)\n", pdp->gsnrc.l);
-
-	for (i = 0; i < 4; i++)
-		printf("%x ", pdp->gsnrc.v[i] & 0xff); /* GTPIE_GSN_ADDR */
-
-	printf("\n");
+	LOGPDPX(DGGSN, LOGL_DEBUG, pdp, "v%u TEID %"PRIu64"x EUA=%s SGSN=%s\n", pdp->version,
+		pdp->version == 0 ? pdp_gettid(pdp->imsi, pdp->nsapi) : pdp->teid_gn,
+		in46a_ntoa(&ia46), inet_ntoa(ia));
 }
 
 static struct {
@@ -101,11 +80,8 @@
 			"cannot lookup GTP genetlink ID\n");
 		return -1;
 	}
-	if (debug) {
-		SYS_ERR(DGGSN, LOGL_NOTICE, 0,
-			"Using the GTP kernel mode (genl ID is %d)\n",
-			gtp_nl.genl_id);
-	}
+	SYS_ERR(DGGSN, LOGL_DEBUG, 0,
+		"Using the GTP kernel mode (genl ID is %d)\n", gtp_nl.genl_id);
 
 	DEBUGP(DGGSN, "Setting route to reach %s via %s\n",
 	       net_arg, GTP_DEVNAME);
diff --git a/sgsnemu/sgsnemu.c b/sgsnemu/sgsnemu.c
index 23cf208..b2927df 100644
--- a/sgsnemu/sgsnemu.c
+++ b/sgsnemu/sgsnemu.c
@@ -974,7 +974,6 @@
 		ret = NULL;
 		goto out;
 	}
-	return ret;
 
 out:
 	fclose(f);

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie22e6a9bc172427e867e7a4001b6c710477a232b
Gerrit-PatchSet: 1
Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>



More information about the gerrit-log mailing list