diff --git a/sbin/ifconfig/lagg.c b/sbin/ifconfig/lagg.c index d5aac9487d66..012414e260c4 100644 --- a/sbin/ifconfig/lagg.c +++ b/sbin/ifconfig/lagg.c @@ -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 #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 @@ -393,15 +393,13 @@ setlaggproto(prop_dictionary_t env, prop_dictionary_t oenv) 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_dictionary_t oenv __unused) 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_dictionary_t oenv __unused) 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