svn commit: r310931 - head/contrib/bsnmp/lib
Ngie Cooper
ngie at FreeBSD.org
Sat Dec 31 11:13:01 UTC 2016
Author: ngie
Date: Sat Dec 31 11:13:00 2016
New Revision: 310931
URL: https://svnweb.freebsd.org/changeset/base/310931
Log:
Use strdup in snmp_parse_server(..) when possible instead of malloc+strcpy
This simplifies the code and mutes a Coverity warning about sc->cport being
improperly allocated
Reported by: Coverity
CID: 1018247
MFC after: 1 week
Modified:
head/contrib/bsnmp/lib/snmpclient.c
Modified: head/contrib/bsnmp/lib/snmpclient.c
==============================================================================
--- head/contrib/bsnmp/lib/snmpclient.c Sat Dec 31 11:12:26 2016 (r310930)
+++ head/contrib/bsnmp/lib/snmpclient.c Sat Dec 31 11:13:00 2016 (r310931)
@@ -1937,20 +1937,18 @@ snmp_parse_server(struct snmp_client *sc
}
/* port */
free(sc->cport);
- if ((sc->cport = malloc(strlen(p + 1) + 1)) == NULL) {
+ if ((sc->cport = strdup(p + 1)) == NULL) {
seterr(sc, "%s", strerror(errno));
return (-1);
}
- strcpy(sc->cport, p + 1);
} else if (p > s) {
/* host */
free(sc->chost);
- if ((sc->chost = malloc(strlen(s) + 1)) == NULL) {
+ if ((sc->chost = strdup(strlen(s))) == NULL) {
seterr(sc, "%s", strerror(errno));
return (-1);
}
- strcpy(sc->chost, s);
}
return (0);
}
More information about the svn-src-all
mailing list