Module Name: src Committed By: yamaguchi Date: Tue Apr 9 08:53:08 UTC 2024
Modified Files: src/sbin/ifconfig: lagg.c Log Message: lagg(4): allocate memory for struct lagg_req by calloc(3) to fix build error on clang To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sbin/ifconfig/lagg.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/ifconfig/lagg.c diff -u src/sbin/ifconfig/lagg.c:1.7 src/sbin/ifconfig/lagg.c:1.8 --- src/sbin/ifconfig/lagg.c:1.7 Mon Apr 8 00:50:49 2024 +++ src/sbin/ifconfig/lagg.c Tue Apr 9 08:53:08 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: lagg.c,v 1.7 2024/04/08 00:50:49 yamaguchi Exp $ */ +/* $NetBSD: lagg.c,v 1.8 2024/04/09 08:53:08 yamaguchi Exp $ */ /* * Copyright (c) 2021 Internet Initiative Japan Inc. @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #if !defined(lint) -__RCSID("$NetBSD: lagg.c,v 1.7 2024/04/08 00:50:49 yamaguchi Exp $"); +__RCSID("$NetBSD: lagg.c,v 1.8 2024/04/09 08:53:08 yamaguchi Exp $"); #endif /* !defined(lint) */ #include <sys/param.h> @@ -393,15 +393,13 @@ setlaggproto(prop_dictionary_t env, prop static int setlaggport(prop_dictionary_t env, prop_dictionary_t oenv __unused) { - struct { - struct lagg_req req; - struct laggreqport port[1]; - } _req; struct lagg_req *req; struct laggreqport *rp; const char *ifname; enum lagg_ioctl ioc; int64_t lpcmd, pri; + int rv; + size_t sz; if (!prop_dictionary_get_string(env, "laggport", &ifname)) { if (lagg_debug) @@ -410,11 +408,15 @@ setlaggport(prop_dictionary_t env, prop_ return -1; } - memset(&_req, 0, sizeof(_req)); - req = (struct lagg_req *)&_req; - rp = &req->lrq_reqports[0]; - req->lrq_nports = 1; + sz = sizeof(*req) + sizeof(req->lrq_reqports[0]) * 1; + req = calloc(1, sz); + if (req == NULL) { + errno = ENOBUFS; + return -1; + } + req->lrq_nports = 1; + rp = &req->lrq_reqports[0]; strlcpy(rp->rp_portname, ifname, sizeof(rp->rp_portname)); ioc = LAGGIOC_NOCMD; @@ -433,15 +435,16 @@ setlaggport(prop_dictionary_t env, prop_ if (ioc != LAGGIOC_NOCMD) { req->lrq_ioctl = ioc; - if (indirect_ioctl(env, SIOCSLAGG, req) == -1) { - if (lagg_debug) { - warn("cmd=%d", ioc); - } - return -1; - } + rv = indirect_ioctl(env, SIOCSLAGG, req); + if (lagg_debug && rv == -1) + warn("cmd=%d", ioc); + } else { + rv = 0; } - return 0; + free(req); + + return rv; } static int