From 70157df618b95ed19af2b2b6161cea409dc6f86e Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Thu, 5 Jan 2017 08:14:20 +0000 Subject: [PATCH] lsock_init_port: address issues with initializing sockaddr_un object - Use strlcpy to ensure p->name doesn't overflow sa.sun_path [*]. - Use SUN_LEN(..) instead of spelling out calculation longhand (inspired by comment by jmallett). Tested with: dgram and stream support with both bsnmpwalk and snmpwalk MFC after: 1 week Reported by: Coverity CID: 1006825 --- contrib/bsnmp/snmpd/trans_lsock.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/contrib/bsnmp/snmpd/trans_lsock.c b/contrib/bsnmp/snmpd/trans_lsock.c index 356fd50d18b1..5c656c856eb2 100644 --- a/contrib/bsnmp/snmpd/trans_lsock.c +++ b/contrib/bsnmp/snmpd/trans_lsock.c @@ -308,10 +308,9 @@ lsock_init_port(struct tport *tp) return (SNMP_ERR_RES_UNAVAIL); } - strcpy(sa.sun_path, p->name); + strlcpy(sa.sun_path, p->name, sizeof(sa.sun_path)); sa.sun_family = AF_LOCAL; - sa.sun_len = strlen(p->name) + - offsetof(struct sockaddr_un, sun_path); + sa.sun_len = SUN_LEN(&sa); (void)remove(p->name); @@ -363,10 +362,9 @@ lsock_init_port(struct tport *tp) return (SNMP_ERR_GENERR); } - strcpy(sa.sun_path, p->name); + strlcpy(sa.sun_path, p->name, sizeof(sa.sun_path)); sa.sun_family = AF_LOCAL; - sa.sun_len = strlen(p->name) + - offsetof(struct sockaddr_un, sun_path); + sa.sun_len = SUN_LEN(&sa); (void)remove(p->name);