From patchwork Fri Aug 28 10:35:11 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5287 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:2a5c:b0:87d:ab56:3700 with SMTP id l28csp977112maz; Fri, 28 Aug 2026 03:35:32 -0700 (PDT) X-Forwarded-Encrypted: i=2; AHgh+RrTn7JJJO0ECz10dwfbdLMMXH8l8r4ZAeCuyiFIVcV5MzY8dqZfThkM7ZHMGBfDSR7w+dOsUIUiUas=@openvpn.net X-Received: by 2002:a05:6808:118d:b0:495:f8a5:8797 with SMTP id 5614622812f47-4b37c302e76mr10325548b6e.0.1787913328826; Fri, 28 Aug 2026 03:35:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1787913328; cv=none; d=google.com; s=arc-20260327; b=DVCSSgF3/dV+nWsSWFFZKfgohK2iPFZ3QJaYW9ieRa1uWa3hZjWpRFywY2c0gzSniw C8vIsTkxiop7P2uMy8WyRrXELJbrcJ8thqWpVlnJ35ubDd0fTPuQIA7hcc0X/Mm9l+Fj JYGusVRMnm6eTxVsXXOWcPpEnE1wPAyo1l492TKQrlhhZEt8fOTNF3nbZ6VktT+cx2ec Ec4izf3AQFRfXETQ5Mmt2MMmpIm8Yt45jI81DaxeC44oDV2rZKnh7khhTy19YVAf+NTr h0xYaf/wnV+o0EarulPvVMZZpQnajA1umfDQb/YuIMSL1KtyLmUGNbMK9u5TxVQ1pdZg xtXA== 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=9+NGczbSW8Yq9mHeInrLF7dkkjMUkEWMIjoL8fFm2x8=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=YUG63jwQsxCZkrBhWVo0kvL4iFtuAoa8f96tnVRMeI9SPiZYPHkC36SJQyuKYWse9x 7JQWoRKOD76CGLf3A5lovVhc5qQugvoGyzaCoNOEw6FkrSgwGfoE5o7lUOC6qfKbkwL0 i0fNY43hp7EZV5VyI/AW1nbYKTDrZypWMu+FNCE3ODqZaN6OfcZer8mdFzYlsk27z2kQ tBlRwb1XVtxg9Rn3baFLEPq1zxF016B0NW3zg7czZx4+pOv+S1cjFk7mKyvJVUn+0GaM WsNoe0ppBEOnju/QmSBlBsa1r0ga20Ofjk6r9yoeZfBqYGdUP5DcU2AyRJJYwW9MdPwV xNWQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=RQBXeYmg; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=HzyPceEf; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=NqesdSsj; 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-4b3a1ba9d8asi1573322b6e.123.2026.08.28.03.35.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Aug 2026 03:35:28 -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=RQBXeYmg; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=HzyPceEf; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=NqesdSsj; 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=9+NGczbSW8Yq9mHeInrLF7dkkjMUkEWMIjoL8fFm2x8=; b=RQBXeYmg9n0L1t5us1ZMLDOhvU E3kxgAl8XCwZD7M+FG4+TzWPXaF5w9TLanYJZ9LeEJzREwZ6IOs61XVHzE2XjmE/vGku68YPDG/v8 oSDclN3diPViYpb2Gh7PqnPhvy8yNfiCDk6AnInoUX20SG4uVW3k557yc+uZZVHIutlo=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wztvh-0006Fd-Lh; Fri, 28 Aug 2026 10:35:25 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wztvh-0006FW-CT for openvpn-devel@lists.sourceforge.net; Fri, 28 Aug 2026 10:35:25 +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=Uv4AgJb864Oo8fEunn0I1p0heq9K3zddfNrinpotJnY=; b=HzyPceEfG5GU+EmZ21DANFFadv fXlO20/RqcgRXZm3JrBGdwlKDZCGgk0wTVaXao1zosxdrBN+uZ7Qfl3br3SeFQtLboM5gpvYmpIhv UoI1iul3JuBZE5OoKLctNeOw/ojP6ApTsh1G6ZK7u8ibAcc5BNkWNkcygaAcGI6D1Wao=; 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=Uv4AgJb864Oo8fEunn0I1p0heq9K3zddfNrinpotJnY=; b=NqesdSsjvu27stq1IQvz/CCJAX sU2aEKAuYaeDki3tmUpLr1VhesoVn0G1ZIj5bq7b9dBUYsoy/+A7aHv8XWfpdbn0K3w92JJKs2Gg0 CCky2orWbU8wcCjjcE45lAaIEz+lXIFZjZjzp7C4OJ5OINUtihaNgwaxr9l1taaId56U=; 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.95) id 1wztvg-0001TE-Fg for openvpn-devel@lists.sourceforge.net; Fri, 28 Aug 2026 10:35:25 +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 67SAZH91013340 for ; Fri, 28 Aug 2026 12:35:17 +0200 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 67SAZHJt013339 for openvpn-devel@lists.sourceforge.net; Fri, 28 Aug 2026 12:35:17 +0200 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Fri, 28 Aug 2026 12:35:11 +0200 Message-ID: <20260828103517.13327-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.53.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-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: Arne Schwabe Change-Id: Ifdd2122a3e60cdb11cc9df67570ab5628bfcdeea Signed-off-by: Arne Schwabe Acked-by: Razvan Cojocaru Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1 [...] 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: 1wztvg-0001TE-Fg Subject: [Openvpn-devel] [PATCH v8] Add helper method to extract a field from a buffer 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: 1874763006703627329 X-GMAIL-MSGID: 1874763006703627329 From: Arne Schwabe Change-Id: Ifdd2122a3e60cdb11cc9df67570ab5628bfcdeea Signed-off-by: Arne Schwabe Acked-by: Razvan Cojocaru Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1855 --- 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/+/1855 This mail reflects revision 8 of this Change. Acked-by according to Gerrit (reflected above): Razvan Cojocaru diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index 046e231..5ce2e39 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -1384,3 +1384,27 @@ fclose(fp); return ret; } + +char * +buf_extract_field(struct buffer *buf, char sep, struct gc_arena *gc) +{ + if (!buf_valid(buf)) + { + return NULL; + } + + const uint8_t *seppos = memchr(BPTR(buf), sep, buf_len(buf)); + if (!seppos) + { + return NULL; + } + size_t field_len = seppos - BPTR(buf); + + char *field = gc_malloc(field_len + 1, false, gc); + + memcpy(field, BPTR(buf), field_len); + field[field_len] = 0; + + buf_advance(buf, field_len + 1); + return field; +} diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index bc5cffb..4471697 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -2243,4 +2243,14 @@ /**@}*/ /* End of Buffer Lists */ +/** + * Extract a field from buf that ends with the \c sep character. The + * returned string is allocated in the gc_arena. If the separator character + * is not found, the function returns the nullptr. + * + * The buffer is also forwarded to the point after the separator character. + */ +char * +buf_extract_field(struct buffer *buf, char sep, struct gc_arena *gc); + #endif /* BUFFER_H */ diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c index ce38bbe..7fb9162 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -456,6 +456,35 @@ /* Check that our own method agrees */ assert_true(string_check_buf(&buf2, CC_PRINT | CC_NULL, CC_CRLF)); assert_string_equal(BSTR(&buf2), "CR_RESPONSE,MTIx"); + gc_free(&gc); +} + +static void +test_buffer_extract_field(void **state) +{ + struct gc_arena gc = gc_new(); + struct buffer buf = alloc_buf_gc(1000, &gc); + assert_null(buf_extract_field(&buf, ',', &gc)); + + buf = alloc_buf_gc(5, &gc); + buf_write(&buf, "12345", 5); + const char *ret = buf_extract_field(&buf, '5', &gc); + assert_string_equal(ret, "1234"); + /* nothing left after the 5 */ + assert_int_equal(buf_len(&buf), 0); + + buf = alloc_buf_gc(5, &gc); + buf_write(&buf, "12345", 5); + ret = buf_extract_field(&buf, '4', &gc); + assert_string_equal(ret, "123"); + + /* 5 should be left */ + assert_int_equal(buf_len(&buf), 1); + assert_memory_equal(buf_bptr(&buf), "5", 1); + + buf = alloc_buf_gc(5, &gc); + buf_write(&buf, "12345", 5); + assert_null(buf_extract_field(&buf, '6', &gc)); gc_free(&gc); } @@ -567,7 +596,8 @@ cmocka_unit_test(test_checked_snprintf), cmocka_unit_test(test_buffer_chomp), cmocka_unit_test(test_buffer_null_terminate), - cmocka_unit_test(test_buffer_parse) + cmocka_unit_test(test_buffer_parse), + cmocka_unit_test(test_buffer_extract_field) }; return cmocka_run_group_tests_name("buffer", tests, NULL, NULL);