From 97dc98862b405b3e14e13f13bab147265f94c6e1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 18 Sep 2017 07:53:02 +0200 Subject: [PATCH] do not use strncpy, then --- src/kernel/equipment.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/kernel/equipment.c b/src/kernel/equipment.c index ca2f68a02..98d6b1e70 100644 --- a/src/kernel/equipment.c +++ b/src/kernel/equipment.c @@ -225,13 +225,15 @@ equipment *get_equipment(const char *eqname) equipment *create_equipment(const char *eqname) { + size_t len = strlen(eqname); eq_entry ent; - if (strlen(eqname) > EQNAMELEN) { + if (len > EQNAMELEN) { log_error("equipment names should be no longer than %d bytes: %s", EQNAMELEN, eqname); + len = EQNAMELEN; } - /* OBS: we require the nul-padding property of strncpy here, so do not use strlcpy: */ - strncpy(ent.key, eqname, EQNAMELEN); + memset(ent.key, 0, EQNAMELEN); + memcpy(ent.key, eqname, len); ent.value = (equipment *)calloc(1, sizeof(equipment)); ent.value->name = strdup(eqname);