forked from github/server
do not use strncpy, then
This commit is contained in:
parent
eca1e5f973
commit
97dc98862b
|
@ -225,13 +225,15 @@ equipment *get_equipment(const char *eqname)
|
||||||
|
|
||||||
equipment *create_equipment(const char *eqname)
|
equipment *create_equipment(const char *eqname)
|
||||||
{
|
{
|
||||||
|
size_t len = strlen(eqname);
|
||||||
eq_entry ent;
|
eq_entry ent;
|
||||||
|
|
||||||
if (strlen(eqname) > EQNAMELEN) {
|
if (len > EQNAMELEN) {
|
||||||
log_error("equipment names should be no longer than %d bytes: %s", EQNAMELEN, eqname);
|
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: */
|
memset(ent.key, 0, EQNAMELEN);
|
||||||
strncpy(ent.key, eqname, EQNAMELEN);
|
memcpy(ent.key, eqname, len);
|
||||||
|
|
||||||
ent.value = (equipment *)calloc(1, sizeof(equipment));
|
ent.value = (equipment *)calloc(1, sizeof(equipment));
|
||||||
ent.value->name = strdup(eqname);
|
ent.value->name = strdup(eqname);
|
||||||
|
|
Loading…
Reference in New Issue