Skip to contentSkip to conversation

Covscan: Fix for missing error checking

PATCH In review Phil Sutter 2 participants 5 messages Aug 21, 2017 – Aug 22, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Covscan: Fix for missing error checking

This series collects patches from v1 dealing with spots where error checking is necessary or recommended.

Minor changes to patches 1 and 2, patch 3 remains unchanged.

Phil Sutter (3):
iproute: Check mark value input
iplink_vrf: Complain if main table is not found
devlink: Check return code of strslashrsplit()

 devlink/devlink.c | 16 ++++++++++++----
 ip/iplink_vrf.c   |  4 +++-
 ip/iproute.c      |  6 ++++--
 3 files changed, 19 insertions(+), 7 deletions(-)
Signature · 1 line
2.13.1
#1 lore raw

PATCH v2 1/3 iproute: Check mark value input

---
Changes since v1:
- Drop newline from end of error message, invarg() already does that.

---
 ip/iproute.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
ip/iproute.c +4 -2
index cb695ad4141a7..5936e2a978bc7 100644
@@ -1493,7 +1493,8 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
 			id = *argv;
 		} else if (strcmp(*argv, "mark") == 0) {
 			NEXT_ARG();
-			get_unsigned(&mark, *argv, 0);
+			if (get_unsigned(&mark, *argv, 0))
+				invarg("invalid mark value", *argv);
 			filter.markmask = -1;
 		} else if (strcmp(*argv, "via") == 0) {
 			int family;
@@ -1710,7 +1711,8 @@ static int iproute_get(int argc, char **argv)
 			idev = *argv;
 		} else if (matches(*argv, "mark") == 0) {
 			NEXT_ARG();
-			get_unsigned(&mark, *argv, 0);
+			if (get_unsigned(&mark, *argv, 0))
+				invarg("invalid mark value", *argv);
 		} else if (matches(*argv, "oif") == 0 ||
 			   strcmp(*argv, "dev") == 0) {
 			NEXT_ARG();
Signature · 1 line
2.13.1
#2 lore raw

PATCH v2 2/3 iplink_vrf: Complain if main table is not found

In reply to Phil Sutter

---
Changes since v1:
- Remove double newline addon.
- Added David's ACK from v1 review.

---
 ip/iplink_vrf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
ip/iplink_vrf.c +3 -1
index 917630e853375..2b85a3a56eb70 100644
@@ -131,7 +131,9 @@ __u32 ipvrf_get_table(const char *name)
 					   &answer.n, sizeof(answer)) < 0) {
 		/* special case "default" vrf to be the main table */
 		if (errno == ENODEV && !strcmp(name, "default"))
-			rtnl_rttable_a2n(&tb_id, "main");
+			if (rtnl_rttable_a2n(&tb_id, "main"))
+				fprintf(stderr,
+					"BUG: RTTable \"main\" not found.\n");
 
 		return tb_id;
 	}
Signature · 1 line
2.13.1
#3 lore raw

PATCH v2 3/3 devlink: Check return code of strslashrsplit()

In reply to Phil Sutter

This function shouldn't fail because all callers of __dl_argv_handle_port() make sure the passed string contains enough slashes already, but better make sure if this changes in future the function won't access uninitialized data.

---
 devlink/devlink.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
devlink/devlink.c +12 -4
index f9bc16c350c40..de41a9f4aae10 100644
@@ -526,18 +526,26 @@ static int __dl_argv_handle_port(char *str,
 				 char **p_bus_name, char **p_dev_name,
 				 uint32_t *p_port_index)
 {
-	char *handlestr = handlestr;
-	char *portstr = portstr;
+	char *handlestr;
+	char *portstr;
 	int err;
 
-	strslashrsplit(str, &handlestr, &portstr);
+	err = strslashrsplit(str, &handlestr, &portstr);
+	if (err) {
+		pr_err("Port identification \"%s\" is invalid\n", str);
+		return err;
+	}
 	err = strtouint32_t(portstr, p_port_index);
 	if (err) {
 		pr_err("Port index \"%s\" is not a number or not within range\n",
 		       portstr);
 		return err;
 	}
-	strslashrsplit(handlestr, p_bus_name, p_dev_name);
+	err = strslashrsplit(handlestr, p_bus_name, p_dev_name);
+	if (err) {
+		pr_err("Port identification \"%s\" is invalid\n", str);
+		return err;
+	}
 	return 0;
 }
 
Signature · 1 line
2.13.1
#4 lore raw
In reply to Phil Sutter
Quoted 10 lines · On Mon, 21 Aug 2017 18:36:49 +0200 Phil Sutter <[email protected]> wrote:

This series collects patches from v1 dealing with spots where error checking is necessary or recommended.

Minor changes to patches 1 and 2, patch 3 remains unchanged.

Phil Sutter (3):
iproute: Check mark value input
iplink_vrf: Complain if main table is not found
devlink: Check return code of strslashrsplit()

Quoted 5 lines
 devlink/devlink.c | 16 ++++++++++++----
 ip/iplink_vrf.c   |  4 +++-
 ip/iproute.c      |  6 ++++--
 3 files changed, 19 insertions(+), 7 deletions(-)

These 3 look fine. Applied