Fix up both r299764 and r299770

nitems was wrong too, as it was being tested against a pointer instead of a buffer on
the stack.

Since the old code was just doing malloc, then strlcpy'ing the contents of the source
buffer into the destination buffer, replace it all with a call to strdup..

Reported by: bde
MFC after: 1 week
X-MFC with: r299764, r299770
Supersized Duncecap to: ngie
Sponsored by: EMC / Isilon Storage Division
This commit is contained in:
Enji Cooper 2016-05-15 00:01:23 +00:00
parent 2ad2bda1a1
commit 2501437203

View File

@ -251,7 +251,7 @@ add_filename(struct snmp_toolinfo *snmptoolctx, const char *filename,
return (0);
}
if ((fstring = malloc(strlen(filename) + 1)) == NULL) {
if ((fstring = strdup(filename)) == NULL) {
warnx("malloc() failed - %s", strerror(errno));
return (-1);
}
@ -264,7 +264,6 @@ add_filename(struct snmp_toolinfo *snmptoolctx, const char *filename,
if (cut != NULL)
asn_append_oid(&(entry->cut), cut);
strlcpy(fstring, filename, nitems(fstring));
entry->name = fstring;
entry->done = done;
SLIST_INSERT_HEAD(&snmptoolctx->filelist, entry, link);