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

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