From 10a0306a2e32c15b97fd7455d3c79b36815b83ba Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Thu, 5 Jan 2017 07:55:17 +0000 Subject: [PATCH] lm_load: fix string copying issues - Ensure `section` doesn't overrun section by using strlcpy instead of strcpy [*]. - Use strdup instead of malloc + strcpy (this wasn't flagged by Coverity, but is an opportunistic change). MFC after: 1 week Reported by: Coverity CID: 1006826 [*] --- contrib/bsnmp/snmpd/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/contrib/bsnmp/snmpd/main.c b/contrib/bsnmp/snmpd/main.c index a4ba7d760f05..a2053e889926 100644 --- a/contrib/bsnmp/snmpd/main.c +++ b/contrib/bsnmp/snmpd/main.c @@ -2324,13 +2324,12 @@ lm_load(const char *path, const char *section) } m->handle = NULL; m->flags = 0; - strcpy(m->section, section); + strlcpy(m->section, section, sizeof(m->section)); - if ((m->path = malloc(strlen(path) + 1)) == NULL) { + if ((m->path = strdup(path)) == NULL) { syslog(LOG_ERR, "lm_load: %m"); goto err; } - strcpy(m->path, path); /* * Make index