From 608b5669ebf13b4e9e3dbceae4a718a1b54b2e7f Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 25 Dec 2013 12:12:10 +0100 Subject: [PATCH] lldpcli: replace safe use of `strcpy` by `strlcpy` The idea is to ease automated testing by removing all use of `strcpy`. See: http://marc.info/?l=openbsd-tech&m=138733933417096&w=2 --- src/client/lldpcli.c | 5 +++-- tests/check_edp.c | 4 ++-- tests/common.c | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/client/lldpcli.c b/src/client/lldpcli.c index a5952dc6..7a82c724 100644 --- a/src/client/lldpcli.c +++ b/src/client/lldpcli.c @@ -192,9 +192,10 @@ _cmd_complete(int all) char **argv = NULL; int argc = 0; int rc = 1; - char *line = malloc(strlen(rl_line_buffer) + 2); + size_t len = strlen(rl_line_buffer); + char *line = malloc(len + 2); if (!line) return -1; - strcpy(line, rl_line_buffer); + strlcpy(line, rl_line_buffer, len + 2); line[rl_point] = 2; /* empty character, will force a word */ line[rl_point+1] = 0; diff --git a/tests/check_edp.c b/tests/check_edp.c index e3e54ef1..0f9905dd 100644 --- a/tests/check_edp.c +++ b/tests/check_edp.c @@ -72,7 +72,7 @@ Extreme Discovery Protocol hardware.h_lport.p_id = "Not used"; hardware.h_lport.p_id_len = strlen(hardware.h_lport.p_id); hardware.h_lport.p_descr = "Not used"; - strcpy(hardware.h_ifname, "eth3"); + strlcpy(hardware.h_ifname, "eth3", sizeof(hardware.h_ifname)); hardware.h_ifindex = 4; chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR; chassis.c_id = macaddress; @@ -236,7 +236,7 @@ Extreme Discovery Protocol hardware.h_lport.p_id = "Not used"; hardware.h_lport.p_id_len = strlen(hardware.h_lport.p_id); hardware.h_lport.p_descr = "Not used"; - strcpy(hardware.h_ifname, "eth3"); + strlcpy(hardware.h_ifname, "eth3", sizeof(hardware.h_ifname)); hardware.h_ifindex = 4; chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR; chassis.c_id = macaddress; diff --git a/tests/common.c b/tests/common.c index 380ecdfb..45869982 100644 --- a/tests/common.c +++ b/tests/common.c @@ -102,7 +102,7 @@ pcap_setup() #endif hardware.h_mtu = 1500; hardware.h_ifindex = 4; - strcpy(hardware.h_ifname, "test"); + strlcpy(hardware.h_ifname, "test", sizeof(hardware.h_ifname)); memcpy(hardware.h_lladdr, macaddress, ETHER_ADDR_LEN); hardware.h_ops = &pcap_ops; /* Prepare chassis */ -- 2.39.5