]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lib: use strlcpy() instead of strcpy()
authorVincent Bernat <bernat@luffy.cx>
Tue, 11 Mar 2014 20:43:59 +0000 (21:43 +0100)
committerVincent Bernat <bernat@luffy.cx>
Tue, 11 Mar 2014 20:43:59 +0000 (21:43 +0100)
This reverts back 27faad4fd79399eda8811d4315c96317ed47a151 but we
introduce a variable for the value of strlen()+1 to make it clear we know
what we are doing.

src/lib/atom-private.c

index fe57e46deea18f1320fa7d6bd680561bf5f180db..0d1a2a29da8a876a25280ce685ba8127e46e6ed8 100644 (file)
@@ -1919,12 +1919,13 @@ read_fixed_precision(lldpctl_atom_t *atom,
                return NULL;
        }
 
-       char *stored = _lldpctl_alloc_in_atom(atom, strlen(result) + 1);
+       size_t len = strlen(result) + 1;
+       char *stored = _lldpctl_alloc_in_atom(atom, len);
        if (stored == NULL) {
                free(result);
                return NULL;
        }
-       strcpy(stored, result);
+       strlcpy(stored, result, len);
        return stored;
 }
 
@@ -2291,6 +2292,7 @@ _lldpctl_atom_set_str_med_caelement(lldpctl_atom_t *atom, lldpctl_key_t key,
 {
        struct _lldpctl_atom_med_caelement_t *el =
            (struct _lldpctl_atom_med_caelement_t *)atom;
+       size_t len;
 
        /* Only local port can be modified */
        if (el->parent->parent->hardware == NULL) {
@@ -2300,10 +2302,11 @@ _lldpctl_atom_set_str_med_caelement(lldpctl_atom_t *atom, lldpctl_key_t key,
 
        switch (key) {
        case lldpctl_k_med_civicaddress_value:
-               if (strlen(value) > 250) goto bad;
-               el->value = _lldpctl_alloc_in_atom(atom, strlen(value) + 1);
+               len = strlen(value) + 1;
+               if (len > 251) goto bad;
+               el->value = _lldpctl_alloc_in_atom(atom, len);
                if (el->value == NULL) return NULL;
-               strcpy((char*)el->value, value);
+               strlcpy((char*)el->value, value, len);
                el->len = strlen(value);
                return atom;
        case lldpctl_k_med_civicaddress_type: