From patchwork Sun Nov 15 13:47:13 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5704 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:9292:b0:11a:f58a:e788 with SMTP id dc18csp104123lab; Sun, 15 Nov 2026 05:47:30 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErG25b3rZwnG5HhGlJn17kvpTke1DhRVk9SP0vXIplI0IcM77fSvYt4X5jT1h0geDWqGHRGmUjawzxo=@openvpn.net X-Received: by 2002:a05:693c:639a:20b0:36c:fdba:ee36 with SMTP id 5a478bee46e88-37966e3a566mr7386395eec.12.1794750450111; Sun, 15 Nov 2026 05:47:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794750450; cv=none; d=google.com; s=arc-20260327; b=dMerBctrAywy6CwaGTG7r1ckLhf7mDLCl2AD4K0MWUmld30ahKN1t9qS3ImdwvYBlY iqmqr6URqN6+eV3CTRU9NYSqSOsc5NyaYs93Hd6yfDzqKSczde07s4jj5Lb5pAFCvYug kcdNITT0we2eDjS5M3DYiRGojXKG9xeGB4lpLf+DwJwdvEE069DaW0lgCMyxRSEVTWhv 55HHgb9LfX0LT4FbAVOFh/2VvzME8bCy4DQDYDISw4Xhot3tSW6bXcChg/JyJNEmba5h 94kEn0/1nBCDSfMbVR6NLFN7/V4hl1yn8WviHEG6wj89TP1eEdTdobyvM1SjwNG/6rM2 +CPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; 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=CXX+Hk2IaS1I+I9gIGVn2G0F1NLWEwIIUh+x69ViDHA=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=VAKFJtFGEKtPg9s/xehWLC+VQz+DEB3fGddCQxHGyHDYpoCVvmvBlReFofnSzlY1F8 zXL4Q01Vuq93Ed8Texd8CIeA+SSz4U9fiCkAZzeW2W8BkQrub+3ZycuNLJD+5TG5FZtf QA1XQbj52WzIfa6ykByg6GVoMuquGQ+vIp2UvG0HibyCsgBT0IHOwFk1TWlbxcHxWs1d KmrySpn5/coylU9AR3eJvC6yf9wPG+jZcoTa7bT21pWqcCMCWKlh/9UwBVMp2kuRGKKR m1zqTBN+Lx8iOGG9sSW9mhds5lNkbAMUnUAWmWeqsrMV8UQGfzb3877K6Oa51Da7CpPj 3Ffg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=fBhmsb1G; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=NWYPzgn6; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=QecAoRfc; 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 5a478bee46e88-3795a67619esi24219614eec.44.2026.11.15.05.47.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Nov 2026 05:47:30 -0800 (PST) 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=fBhmsb1G; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=NWYPzgn6; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=QecAoRfc; 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-Unsubscribe-Post: List-Owner; bh=CXX+Hk2IaS1I+I9gIGVn2G0F1NLWEwIIUh+x69ViDHA=; b=fBhmsb1GFw2x8K LOlyqsMN2R2hiqeAuP6kxFdPHTvDNNjaLXD+7Fdmw7GvHvfgyCPq0z4gLFGYPzXbqnZGtXtk3HJmw 4wllbB6smC/iLJF3LLpMwsxlYD0CQxlueXp3oY37LJbEVgq1CdtAtKNLpwgI1NIx1aSRvIs1QeXhP Byw=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xSaZt-000000007HS-0w9T; Sun, 15 Nov 2026 13:47:29 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xSaZr-000000007HK-01Or for openvpn-devel@lists.sourceforge.net; Sun, 15 Nov 2026 13:47:27 +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-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=aOqSp7O2wVLuOLzoEjo0SYrHYGHkRulAJYVh2DMNN4o=; b=NWYPzgn6vbg6z8MPl8rBBv8PJ3 /X+oY4V9h+GbR1JcujMn2imX74iaJACMXHcXQB4bjbALuwnDI8xnGoqOvwRARxvuJ87/5drL0qCKJ pNqO5641qTgmnCCf8bWX4y6eze1AnDBObk0rAA9cd5KXB6rxocqF7SPObiusCAgKqPEU=; 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-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=aOqSp7O2wVLuOLzoEjo0SYrHYGHkRulAJYVh2DMNN4o=; b=QecAoRfcpNEQCNb/bPanxtMuVC xLauwzqmotqNmirDS9HbaEBPGf1rU7QF60dHE3mBu+TZR8ts7YokoKcDcFl/ee0jG/6IQ2RmeBH4u gHxGe7ycYnb2B1H05JV8dRIFTjx2yf8tq8zoV7Awp6T3ulv+OV5T+D9sAahs0z+ipnFA=; Received: from [193.149.48.129] (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.100.1) id 1xSaZq-000000001HC-0O5k for openvpn-devel@lists.sourceforge.net; Sun, 15 Nov 2026 13:47:26 +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 6AFDlJ62022589 for ; Sun, 15 Nov 2026 14:47:19 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AFDlJUM022588 for openvpn-devel@lists.sourceforge.net; Sun, 15 Nov 2026 14:47:19 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Sun, 15 Nov 2026 14:47:13 +0100 Message-ID: <20261115134718.22576-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.55.0 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-1.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: Alexandre Laroche Several allocations were used without a NULL check, so a failed allocation crashed the server on a NULL pointer instead of stopping with "Out of Memory" like the rest of the code: 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: 1xSaZq-000000001HC-0O5k Subject: [Openvpn-devel] [PATCH v2] Check the result of unchecked allocations in the server 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: 1881932247639482354 X-GMAIL-MSGID: 1881932247639482354 From: Alexandre Laroche Several allocations were used without a NULL check, so a failed allocation crashed the server on a NULL pointer instead of stopping with "Out of Memory" like the rest of the code: - multi_init(): calloc() of m->instances; the server started and then crashed in multi_assign_peer_id() on the first client - generate_auth_token(), verify_user_pass(): strdup() of auth tokens; generate_auth_token() then called strdup(NULL) - override_locked_username(): strdup() of the override username; the strlcpy() from locked_username then crashed (with --auth-gen-token) - backend_x509_get_serial_hex(): malloc() of the serial buffer, which BN_bn2binpad() then wrote to Use string_alloc(..., NULL) instead of strdup(), add check_malloc_return() after the calloc(), and allocate the serial buffer with gc_malloc(), which also copes with a zero serial number (BN_num_bytes() is 0 there, and malloc(0) may return NULL). GitHub: closes OpenVPN/openvpn#1142 Assisted-by: Claude Code:claude-opus-5-5 Change-Id: I603321ae6893dbdb054deae5a9bff5e52cbb7429 Signed-off-by: Alexandre Laroche Acked-by: Razvan Cojocaru Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2155 --- 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/+/2155 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Razvan Cojocaru diff --git a/src/openvpn/auth_token.c b/src/openvpn/auth_token.c index 84558af..10c656e 100644 --- a/src/openvpn/auth_token.c +++ b/src/openvpn/auth_token.c @@ -275,7 +275,7 @@ /* free the auth-token if defined, we will replace it with a new one */ free(multi->auth_token); - multi->auth_token = strdup((char *)BPTR(&session_token)); + multi->auth_token = string_alloc((char *)BPTR(&session_token), NULL); dmsg(D_SHOW_KEYS, "Generated token for client: %s (%s)", multi->auth_token, up->username); @@ -285,7 +285,7 @@ * Save the initial auth token to continue using the same session ID * and timestamp in updates */ - multi->auth_token_initial = strdup(multi->auth_token); + multi->auth_token_initial = string_alloc(multi->auth_token, NULL); } gc_free(&gc); diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 3f514d6..662fc9d 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -395,6 +395,7 @@ m->max_clients = t->options.max_clients; m->instances = calloc(m->max_clients, sizeof(struct multi_instance *)); + check_malloc_return(m->instances); m->top.c2.event_set = t->c2.event_set; @@ -2653,7 +2654,7 @@ } multi->locked_original_username = multi->locked_username; - multi->locked_username = strdup(options->override_username); + multi->locked_username = string_alloc(options->override_username, NULL); /* Override also the common name if username should be set as common * name */ diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index 0cdec1e..9b3f86d 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -1658,7 +1658,7 @@ * using the same session ID and initial timestamp in new tokens */ if (!multi->auth_token_initial && (ks->auth_token_state_flags & AUTH_TOKEN_HMAC_OK)) { - multi->auth_token_initial = strdup(up->password); + multi->auth_token_initial = string_alloc(up->password, NULL); } if (session->opt->auth_token_call_auth) @@ -1777,7 +1777,7 @@ if (!multi->auth_token && (ks->auth_token_state_flags & AUTH_TOKEN_HMAC_OK) && !(ks->auth_token_state_flags & AUTH_TOKEN_EXPIRED)) { - multi->auth_token = strdup(up->password); + multi->auth_token = string_alloc(up->password, NULL); } /* diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_openssl.c index 0c36cf2..3f1200d 100644 --- a/src/openvpn/ssl_verify_openssl.c +++ b/src/openvpn/ssl_verify_openssl.c @@ -323,11 +323,10 @@ const ASN1_INTEGER *asn1_i = X509_get_serialNumber(cert); BIGNUM *bn_serial = ASN1_INTEGER_to_BN(asn1_i, NULL); int len_serial = BN_num_bytes(bn_serial); - unsigned char *buf = malloc(len_serial); + unsigned char *buf = gc_malloc(len_serial, false, gc); BN_bn2binpad(bn_serial, buf, len_serial); char *ret = format_hex_ex(buf, len_serial, 0, 1, ":", gc); - free(buf); BN_free(bn_serial); return ret;