]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lldpcli: replace safe use of `strcpy` by `strlcpy`
authorVincent Bernat <bernat@luffy.cx>
Wed, 25 Dec 2013 11:12:10 +0000 (12:12 +0100)
committerVincent Bernat <bernat@luffy.cx>
Wed, 25 Dec 2013 11:12:10 +0000 (12:12 +0100)
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
tests/check_edp.c
tests/common.c

index a5952dc69514141713b831b173e0f3729c5d013e..7a82c724c870bf3c3c30c2ab33e4c16c4cb4197c 100644 (file)
@@ -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;
 
index e3e54ef109f7a22e5a32e466a732a7d0a422dbbb..0f9905dd2e536efa0292f0a083d8dca975ecbf07 100644 (file)
@@ -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;
index 380ecdfb742768ea54d41db0121d376dd4a596ca..45869982deeeace84bc3500de54a571a1f4fbb5c 100644 (file)
@@ -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 */