From patchwork Thu Oct 9 20:59:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4492 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:7d42:b0:72f:f16c:e055 with SMTP id fr2csp1919552mab; Thu, 9 Oct 2025 14:00:15 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVhueCQ1hZ4AyvR4mVPJX6/xTQjHl7AvkN+Wl+PKk549xGkqLqghsnIBMmXHmfWLi+ya5OwW2b4SUQ=@openvpn.net X-Google-Smtp-Source: AGHT+IFqdLjJ+w5bcsTjPWrq91pl8+xgmhp1D1/qNvwDFwZFGWSWfJdB0G2pxqmYVe2Bi/ECiT7Y X-Received: by 2002:a05:6808:1586:b0:43f:2c27:b720 with SMTP id 5614622812f47-4417b2fad79mr3866003b6e.20.1760043614822; Thu, 09 Oct 2025 14:00:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1760043614; cv=none; d=google.com; s=arc-20240605; b=YZMkPtwpeXGOOQ/Vik0j+awb0pBGLvBuNbz5lPAJKe7kZkCzeoDakhartXp/6uoiQk nTkULn8xlL79NuPnfSIsPBhdW3IHGmDY9Ssnw7ZVAcRlqNIC6KTFfUdV/UB2rLXhZD6L 7Be6UgpcR4R9R0okmyEV56YEcMHqfb3XMMGaY9/HixXiWr773zxhKKD5k5QvnmeF3WcW srmlVzepYOwqw84t28bbvcNogiQ6grAvlbV6EVwHL+vFOgeeGxJeE2EZZcaoehIr5BI6 UAE/ZBpnGNm89S7PndawTjMdQ2iXNqtI6jkXH84lWvnqpa9enwlFpGCs7wX4+HHcs24M Eg7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=LMutH4pADTnCjY3jIZJYANSFj/AkLwZ2U6LpyQO6lQw=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=VuhI/Cpj2rnYLEQM0sPqRXv/sfmzD/WUwgzt1SRpCqq8rNPep7WUQ4Lx2KxhZTZ15N d3oxXEnoGqOGOBn+5cOOTKqaKy9rE+PJ/15LUL3N3Vi0zyntNlIHLJDYTGsl2YNNJKj5 QyJc2+k9oFeQxoAjy6IgWWMoAnm1/W7h6DD1JsGsHrCBFRqtkBBK5GZSbo1vHzmBk2T1 07pc2y6BDr8v1aiPDoYhOwfvTkDJFkdtdWrEvohTvKMjDdEO/BF6YV/UM2ek91rNKS92 pXOSb/tJUQMurb9FFVEJmT7nCrOCUdFuI3cqio2Q3UJ/qL3826tl6fuLsUIpHCnu5g+V LUYA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=TtdkO5p6; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=nC+Q5bQY; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=ELgVHwTr; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 5614622812f47-441989c890csi101032b6e.333.2025.10.09.14.00.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Oct 2025 14:00:14 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=TtdkO5p6; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=nC+Q5bQY; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=ELgVHwTr; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LMutH4pADTnCjY3jIZJYANSFj/AkLwZ2U6LpyQO6lQw=; b=TtdkO5p6ICahrPN5kBiALA3Mkz m+Li2E9/Bq+YjaJ0Em4kKAsvXest7cimXh40vIRstRdcqL1EfBoQWNL6Vzc6aLXtJgauvElC3i/FR W3MSK8+1ee+DPVQMmesK1bKCHRrxVQmMlavf2vEu5ja6sWPQwwQ+BEiXkMZaF+OCHd7A=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1v6xk7-0000wT-2r; Thu, 09 Oct 2025 21:00:07 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1v6xk5-0000wL-8I for openvpn-devel@lists.sourceforge.net; Thu, 09 Oct 2025 21:00:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=07v5a50kfImFKcI48dhnz1zX0IrtOjCYLgdG7BJRLvY=; b=nC+Q5bQYTdxeIBUPUtG2A042nQ FoRktWz19+0JUYUaHMGdJBwLl4JBPd9gU0xqfjod3fxi6drLLhKaXSibOMXJrAIFdfRc25ChAd1U7 U13qZZTI9SsSMpJsdxH8TKgTEDmOBaOy9/cv7P2kRbbyI9heQtaIM5p1Z7w/acLrmBkQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=07v5a50kfImFKcI48dhnz1zX0IrtOjCYLgdG7BJRLvY=; b=ELgVHwTr9gIM37ObBqJ/YMSC7Y oOfPNHb/hj0EoHlveH8FaAgL0Mx84qWBUTQVVDiaenRbrpfa3RIyhAjKDy2rycuhvbsQ9rxvNxC0o C6SIKZZUMVHuGqBQxbFHXMdaJn7v57ivvfY+79W4IyhkjbjXuKqjWgxvUjZH1j+z8hZk=; Received: from [193.149.48.134] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1v6xk4-0001wr-2Z for openvpn-devel@lists.sourceforge.net; Thu, 09 Oct 2025 21:00:05 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 599KxqcR032320 for ; Thu, 9 Oct 2025 22:59:52 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 599KxqWH032319 for openvpn-devel@lists.sourceforge.net; Thu, 9 Oct 2025 22:59:52 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 9 Oct 2025 22:59:46 +0200 Message-ID: <20251009205951.32301-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Frank Lichtenheld Replace where it is useful. While here also add a missing cast in atoi_constrained. Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1v6xk4-0001wr-2Z Subject: [Openvpn-devel] [PATCH v6] options: Review use of positive_atoi vs atoi_constrained X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1845539492528082191?= X-GMAIL-MSGID: =?utf-8?q?1845539492528082191?= From: Frank Lichtenheld Replace where it is useful. While here also add a missing cast in atoi_constrained. Change-Id: Id440917f433aab1a7db608ba04fa95ba47c2ddde Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1153 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1153 This mail reflects revision 6 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/src/openvpn/options.c b/src/openvpn/options.c index f2e6dec..e6e0b6f 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -6415,21 +6415,15 @@ else if (streq(p[0], "tun-mtu-max") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION); - int max_mtu = positive_atoi(p[1], msglevel); - if (max_mtu < 68 || max_mtu > 65536) - { - msg(msglevel, "--tun-mtu-max value '%s' is invalid", p[1]); - } - else - { - options->ce.tun_mtu_max = max_mtu; - } + atoi_constrained(p[1], &options->ce.tun_mtu_max, p[0], TUN_MTU_MAX_MIN, 65536, msglevel); } else if (streq(p[0], "tun-mtu-extra") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION); - options->ce.tun_mtu_extra = positive_atoi(p[1], msglevel); - options->ce.tun_mtu_extra_defined = true; + if (atoi_constrained(p[1], &options->ce.tun_mtu_extra, p[0], 0, 65536, msglevel)) + { + options->ce.tun_mtu_extra_defined = true; + } } else if (streq(p[0], "max-packet-size") && p[1] && !p[2]) { @@ -6461,11 +6455,8 @@ else if (streq(p[0], "fragment") && p[1] && !p[3]) { VERIFY_PERMISSION(OPT_P_MTU | OPT_P_CONNECTION); - options->ce.fragment = positive_atoi(p[1], msglevel); - - if (options->ce.fragment < 68) + if (!atoi_constrained(p[1], &options->ce.fragment, p[0], 68, INT_MAX, msglevel)) { - msg(msglevel, "--fragment needs to be at least 68"); goto err; } @@ -7139,12 +7130,14 @@ VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); if (p[1]) { - int mssfix = positive_atoi(p[1], msglevel); - /* can be 0, but otherwise it needs to be high enough so we can - * substract room for headers. */ - if (mssfix != 0 && (mssfix < TLS_CHANNEL_MTU_MIN || mssfix > UINT16_MAX)) + int mssfix; + if (!atoi_constrained(p[1], &mssfix, p[0], 0, UINT16_MAX, msglevel)) { - msg(msglevel, "--mssfix value '%s' is invalid", p[1]); + goto err; + } + if (mssfix != 0 && mssfix < TLS_CHANNEL_MTU_MIN) + { + msg(msglevel, "mssfix needs to be >= %d, not %d", TLS_CHANNEL_MTU_MIN, mssfix); goto err; } @@ -7397,7 +7390,7 @@ else if (streq(p[0], "max-routes-per-client") && p[1] && !p[2]) { VERIFY_PERMISSION(OPT_P_INHERIT); - options->max_routes_per_client = max_int(positive_atoi(p[1], msglevel), 1); + atoi_constrained(p[1], &options->max_routes_per_client, p[0], 1, INT_MAX, msglevel); } else if (streq(p[0], "client-cert-not-required") && !p[1]) { @@ -9216,8 +9209,6 @@ } else if (streq(p[0], "keying-material-exporter") && p[1] && p[2]) { - int ekm_length = positive_atoi(p[2], msglevel); - VERIFY_PERMISSION(OPT_P_GENERAL); if (strncmp(p[1], "EXPORTER", 8)) @@ -9231,14 +9222,14 @@ msg(msglevel, "Keying material exporter label must not be '" EXPORT_KEY_DATA_LABEL "'."); } - if (ekm_length < 16 || ekm_length > 4095) + + if (!atoi_constrained(p[2], &options->keying_material_exporter_length, + p[0], 16, 4095, msglevel)) { - msg(msglevel, "Invalid keying material exporter length"); goto err; } options->keying_material_exporter_label = p[1]; - options->keying_material_exporter_length = ekm_length; } else if (streq(p[0], "allow-recursive-routing") && !p[1]) { @@ -9273,15 +9264,14 @@ } else if (streq(p[0], "vlan-pvid") && p[1] && !p[2]) { + int vlan_pvid; VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_INSTANCE); - options->vlan_pvid = positive_atoi(p[1], msglevel); - if (options->vlan_pvid < OPENVPN_8021Q_MIN_VID - || options->vlan_pvid > OPENVPN_8021Q_MAX_VID) + if (!atoi_constrained(p[1], &vlan_pvid, p[0], + OPENVPN_8021Q_MIN_VID, OPENVPN_8021Q_MAX_VID, msglevel)) { - msg(msglevel, "the parameter of --vlan-pvid parameters must be >= %u and <= %u", - OPENVPN_8021Q_MIN_VID, OPENVPN_8021Q_MAX_VID); goto err; } + options->vlan_pvid = (uint16_t)vlan_pvid; } else {