This commit is contained in:
Enno Rehling 2017-09-18 17:26:50 +02:00
commit 6ab35d80d0
2 changed files with 9 additions and 3 deletions

View File

@ -67,8 +67,12 @@ static int keys_size(int n) {
assert(n > 0 && n <= 4096); assert(n > 0 && n <= 4096);
if (n <= 1) return 1; if (n <= 1) return 1;
if (n <= 4) return 4; if (n <= 4) return 4;
if (n <= 8) return 8;
if (n <= 16) return 16; if (n <= 16) return 16;
if (n <= 256) return 256; if (n <= 256) return 256;
if (n <= 512) return 512;
if (n <= 1024) return 1024;
if (n <= 2048) return 2048;
return 4096; return 4096;
} }

View File

@ -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);