Blame SOURCES/0007-Avoiding-null-pointer-dereference.patch

dc4502
From 2a352d36e2ecc3df4b1c2155b3fd2fa11f95e0bc Mon Sep 17 00:00:00 2001
dc4502
From: klebertarcisio <klebertarcisio@yahoo.com.br>
dc4502
Date: Fri, 2 Apr 2021 19:54:03 -0300
dc4502
Subject: [PATCH 7/8] Avoiding null pointer dereference
dc4502
dc4502
---
dc4502
 ctrl_iface.c   | 2 ++
dc4502
 dcbtool_cmds.c | 2 ++
dc4502
 lldp_8021qaz.c | 4 ++++
dc4502
 lldp_dcbx.c    | 4 ++++
dc4502
 4 files changed, 12 insertions(+)
dc4502
dc4502
diff --git a/ctrl_iface.c b/ctrl_iface.c
dc4502
index 666f7c8..5f86fd2 100644
dc4502
--- a/ctrl_iface.c
dc4502
+++ b/ctrl_iface.c
dc4502
@@ -180,6 +180,8 @@ int clif_iface_attach(struct clif_data *clifd,
dc4502
 	} else {
dc4502
 		tlv = strdup(ibuf);
dc4502
 		str = tlv;
dc4502
+		if (!str)
dc4502
+			goto err_tlv;
dc4502
 		str++;
dc4502
 		/* Count number of TLV Modules */
dc4502
 		tokenize = strtok(str, delim);
dc4502
diff --git a/dcbtool_cmds.c b/dcbtool_cmds.c
dc4502
index 0846f83..e1c76c4 100644
dc4502
--- a/dcbtool_cmds.c
dc4502
+++ b/dcbtool_cmds.c
dc4502
@@ -373,6 +373,8 @@ int handle_dcb_cmds(struct clif *clif, int argc, char *argv[], int raw)
dc4502
 	}
dc4502
 
dc4502
 	cmd_args = get_cmd_args();
dc4502
+	if (!cmd_args)
dc4502
+		return -1;
dc4502
 
dc4502
 	if (get_feature() == FEATURE_DCBX)
dc4502
 		snprintf(cbuf, sizeof(cbuf), "%c%01x%02x%02x%s",
dc4502
diff --git a/lldp_8021qaz.c b/lldp_8021qaz.c
dc4502
index 8bb2bc9..5fccbe4 100644
dc4502
--- a/lldp_8021qaz.c
dc4502
+++ b/lldp_8021qaz.c
dc4502
@@ -1959,6 +1959,10 @@ int ieee8021qaz_rchange(struct port *port, struct lldp_agent *agent,
dc4502
 	if (tlv->type == TYPE_1) {
dc4502
 		clear_ieee8021qaz_rx(qaz_tlvs);
dc4502
 		rx = malloc(sizeof(*rx));
dc4502
+		if (!rx) {
dc4502
+			LLDPAD_INFO("failed malloc for rx\n");
dc4502
+			return TLV_ERR;
dc4502
+		}
dc4502
 		memset(rx, 0, sizeof(*rx));
dc4502
 		qaz_tlvs->rx = rx;
dc4502
 		qaz_tlvs->ieee8021qazdu = 0;
dc4502
diff --git a/lldp_dcbx.c b/lldp_dcbx.c
dc4502
index 3567634..66df857 100644
dc4502
--- a/lldp_dcbx.c
dc4502
+++ b/lldp_dcbx.c
dc4502
@@ -695,6 +695,10 @@ int dcbx_rchange(struct port *port, struct lldp_agent *agent, struct unpacked_tl
dc4502
 	 */
dc4502
 	if (tlv->type == TYPE_1) {
dc4502
 		manifest = malloc(sizeof(*manifest));
dc4502
+		if (!manifest) {
dc4502
+			LLDPAD_INFO("failed malloc for manifest\n");
dc4502
+			return TLV_ERR;
dc4502
+		}
dc4502
 		memset(manifest, 0, sizeof(*manifest));
dc4502
 		dcbx->manifest = manifest;
dc4502
 		dcbx->dcbdu = 0;
dc4502
-- 
dc4502
2.31.1
dc4502