]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lib: use strlcpy and snprintf instead of strcpy and sprintf
authorVincent Bernat <bernat@luffy.cx>
Sat, 29 Dec 2012 18:54:43 +0000 (19:54 +0100)
committerVincent Bernat <bernat@luffy.cx>
Sat, 29 Dec 2012 18:59:04 +0000 (19:59 +0100)
Even if we used strcpy and sprintf safely, use strlcpy and snprintf to
show that we know what we do (and make OpenBSD linker happy).

src/daemon/lldpd.c
src/lib/atom-private.c

index dd9124d710a61ed1fbeb179e502cdc82e2418b22..39f2d8b23867b258be05e6664e9928e5e3d03607 100644 (file)
@@ -667,8 +667,8 @@ lldpd_hide_ports(struct lldpd *cfg, struct lldpd_hardware *hardware, int mask) {
                                break;
                        }
                        if (buffer[0])
-                               strcat(buffer, ", ");
-                       strcat(buffer, cfg->g_protocols[i].name);
+                               strncat(buffer, ", ", 2);
+                       strncat(buffer, cfg->g_protocols[i].name, strlen(cfg->g_protocols[i].name));
                }
        }
        log_debug("smartfilter", "%s: %s: %d visible neighbors (out of %d)",
index bfb0b0992a530ffd94d7c326d5de9805812443ec..185240f9eb2619d8b922f107dbd36770d8734f4e 100644 (file)
@@ -2146,7 +2146,7 @@ _lldpctl_atom_set_str_med_caelement(lldpctl_atom_t *atom, lldpctl_key_t key,
                if (strlen(value) > 250) goto bad;
                el->value = _lldpctl_alloc_in_atom(atom, strlen(value) + 1);
                if (el->value == NULL) return NULL;
-               strcpy((char*)el->value, value);
+               strlcpy((char*)el->value, value, strlen(value) + 1);
                el->len = strlen(value);
                return atom;
        default:
@@ -2611,9 +2611,9 @@ _lldpctl_dump_in_atom(lldpctl_atom_t *atom,
                return NULL;
 
        for (i = 0; (i < size) && (max == 0 || i < max); i++)
-               sprintf(buffer + i * 3, "%02x%c", *(u_int8_t*)(input + i), sep);
+               snprintf(buffer + i * 3, 4, "%02x%c", *(u_int8_t*)(input + i), sep);
        if (max > 0 && size > max)
-               sprintf(buffer + i * 3, "%s", truncation);
+               snprintf(buffer + i * 3, sizeof(truncation) + 1, "%s", truncation);
        else
                *(buffer + i*3 - 1) = 0;
        return buffer;