1From 61291de03cb6dd1aea2a633eb72951f3fe453e7f Mon Sep 17 00:00:00 2001
2From: Aaron Conole <aconole@redhat.com>
3Date: Mon, 3 Aug 2020 15:33:08 -0400
4Subject: [PATCH 8/9] stringops: fix some string copy errors
5
6Reported when using gcc-10.
7
8Signed-off-by: Aaron Conole <aconole@redhat.com>
9---
10 dcb_protocol.c | 13 ++++---------
11 lldp/ports.c   |  2 +-
12 2 files changed, 5 insertions(+), 10 deletions(-)
13
14diff --git a/dcb_protocol.c b/dcb_protocol.c
15index 75ca139..930251b 100644
16--- a/dcb_protocol.c
17+++ b/dcb_protocol.c
18@@ -2257,13 +2257,8 @@ cmd_status get_bwg_descrpt(char *device_name, u8 bwgid, char **name)
19
20 	if ((it != NULL) &&
21 		(bwgid < it->second->max_pgid_desc)) {
22-		size = (int)strlen(it->second->pgid_desc[bwgid]) +
23-			sizeof(char);  /* Localization OK */
24-		*name = (char*)malloc(size);
25-		if (*name != NULL) {
26-			strncpy(*name, it->second->pgid_desc[bwgid],
27-					size); /* Localization OK */
28-		} else {
29+		*name = strdup(it->second->pgid_desc[bwgid]);
30+		if (*name == NULL) {
31 			goto Error;
32 		}
33 	} else {
34@@ -2272,9 +2267,9 @@ cmd_status get_bwg_descrpt(char *device_name, u8 bwgid, char **name)
35 			size = (int)strlen(
36 				attribs.descript.pgid_desc[bwgid]) +
37 				sizeof(char);
38-			*name = (char*)malloc(size);
39+			*name = (char*)calloc(size, sizeof(char));
40 			if (*name != NULL) {
41-				memcpy(*name, attribs.descript.pgid_desc[bwgid], size); /* Localization OK */
42+				memcpy(*name, attribs.descript.pgid_desc[bwgid], size - 1); /* Localization OK */
43 			} else {
44 				goto Error;
45 			}
46diff --git a/lldp/ports.c b/lldp/ports.c
47index 6384f14..9b681f7 100644
48--- a/lldp/ports.c
49+++ b/lldp/ports.c
50@@ -264,7 +264,7 @@ struct port *add_port(int ifindex, const char *ifname)
51 	memset(newport, 0, sizeof(*newport));
52 	newport->ifindex = ifindex;
53 	newport->next = NULL;
54-	strncpy(newport->ifname, ifname, IFNAMSIZ);
55+	strncpy(newport->ifname, ifname, IFNAMSIZ - 1);
56
57 	newport->bond_master = is_bond(ifname);
58 	/* Initialize relevant port variables */
59--
602.28.0
61
62