[MERGED] libosmo-sccp[master]: vty: Check returncode of osmo_ss7_pointcode_parse()

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
Sat Jul 8 10:29:38 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: vty: Check returncode of osmo_ss7_pointcode_parse()
......................................................................


vty: Check returncode of osmo_ss7_pointcode_parse()

The result of osmo_ss7_pointcode_parse() is currently not
checked. This means that -EINVAL could end up as value
in the pointcode configuration.

Check the return code of osmo_ss7_pointcode_parse() and
exit the VTY command with CMD_WARNING if the returned
pointcode is < 0

Change-Id: Iae6d92b1d135063dfd0a26bc23a89802cb3b1a78
---
M src/osmo_ss7_vty.c
1 file changed, 51 insertions(+), 8 deletions(-)

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



diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c
index 8e40474..b06f554 100644
--- a/src/osmo_ss7_vty.c
+++ b/src/osmo_ss7_vty.c
@@ -165,7 +165,11 @@
 	"Point Code\n")
 {
 	struct osmo_ss7_instance *inst = vty->index;
-	uint32_t pc = osmo_ss7_pointcode_parse(inst, argv[0]);
+	int pc = osmo_ss7_pointcode_parse(inst, argv[0]);
+	if (pc < 0) {
+		vty_out(vty, "Invalid point code (%s)%s", argv[0], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
 
 	inst->cfg.primary_pc = pc;
 	return CMD_SUCCESS;
@@ -271,10 +275,20 @@
 {
 	struct osmo_ss7_route_table *rtable = vty->index;
 	struct osmo_ss7_route *rt;
-	uint32_t dpc = osmo_ss7_pointcode_parse(rtable->inst, argv[0]);
-	uint32_t mask = osmo_ss7_pointcode_parse_mask_or_len(rtable->inst, argv[1]);
+	int dpc = osmo_ss7_pointcode_parse(rtable->inst, argv[0]);
+	int mask = osmo_ss7_pointcode_parse_mask_or_len(rtable->inst, argv[1]);
 	const char *ls_name = argv[2];
 	unsigned int argind;
+
+	if (dpc < 0) {
+		vty_out(vty, "Invalid point code (%s)%s", argv[0], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	if (mask < 0) {
+		vty_out(vty, "Invalid point code (%s)%s", argv[1], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
 
 	rt = osmo_ss7_route_create(rtable, dpc, mask, ls_name);
 	if (!rt) {
@@ -307,8 +321,18 @@
 {
 	struct osmo_ss7_route_table *rtable = vty->index;
 	struct osmo_ss7_route *rt;
-	uint32_t dpc = osmo_ss7_pointcode_parse(rtable->inst, argv[0]);
-	uint32_t mask = osmo_ss7_pointcode_parse_mask_or_len(rtable->inst, argv[1]);
+	int dpc = osmo_ss7_pointcode_parse(rtable->inst, argv[0]);
+	int mask = osmo_ss7_pointcode_parse_mask_or_len(rtable->inst, argv[1]);
+
+	if (dpc < 0) {
+		vty_out(vty, "Invalid point code (%s)%s", argv[0], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	if (mask < 0) {
+		vty_out(vty, "Invalid point code (%s)%s", argv[1], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
 
 	rt = osmo_ss7_route_find_dpc_mask(rtable, dpc, mask);
 	if (!rt) {
@@ -770,9 +794,16 @@
 	struct osmo_ss7_as *as = vty->index;
 	struct osmo_ss7_routing_key *rkey = &as->cfg.routing_key;
 	int argind;
+	int pc;
 
+	pc = osmo_ss7_pointcode_parse(as->inst, argv[1]);
+	if (pc < 0) {
+		vty_out(vty, "Invalid point code (%s)%s", argv[1], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	rkey->pc = pc;
 	rkey->context = atoi(argv[0]);
-	rkey->pc = osmo_ss7_pointcode_parse(as->inst, argv[1]);
 	argind = 2;
 
 	if (argind < argc && !strcmp(argv[argind], "si")) {
@@ -799,7 +830,11 @@
 	"New Point Code\n")
 {
 	struct osmo_ss7_as *as = vty->index;
-	uint32_t pc = osmo_ss7_pointcode_parse(as->inst, argv[0]);
+	int pc = osmo_ss7_pointcode_parse(as->inst, argv[0]);
+	if (pc < 0) {
+		vty_out(vty, "Invalid point code (%s)%s", argv[0], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
 
 	if (as->cfg.proto != OSMO_SS7_ASP_PROT_IPA) {
 		vty_out(vty, "Only IPA type AS support point-code override. "
@@ -1208,11 +1243,19 @@
 DEFUN(cs7_sccpaddr_pc, cs7_sccpaddr_pc_cmd,
       "point-code POINT_CODE", "Add point-code Number\n" "PC\n")
 {
+	int pc;
 	struct osmo_sccp_addr_entry *entry =
 	    (struct osmo_sccp_addr_entry *)vty->index;
 	OSMO_ASSERT(entry);
+
+	pc = osmo_ss7_pointcode_parse(entry->inst, argv[0]);
+	if (pc < 0) {
+		vty_out(vty, "Invalid point code (%s)%s", argv[0], VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
 	entry->addr.presence |= OSMO_SCCP_ADDR_T_PC;
-	entry->addr.pc = osmo_ss7_pointcode_parse(entry->inst, argv[0]);
+	entry->addr.pc = pc;
 	return CMD_SUCCESS;
 }
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iae6d92b1d135063dfd0a26bc23a89802cb3b1a78
Gerrit-PatchSet: 3
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list