From patchwork Fri Dec 13 16:47:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Lichtenheld X-Patchwork-Id: 3999 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:1f13:b0:5e7:b9eb:58e8 with SMTP id hs19csp545505mab; Fri, 13 Dec 2024 09:12:23 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVtcM23bUZAA7qCgsNzT+AuX+Zoyj6d14e1WLTEHR7FZ8ul2qYxWuUHRxX3UtOZb8NehKOGHkeTWiQ=@openvpn.net X-Google-Smtp-Source: AGHT+IEn2UeUogs0jCJDumX+Be2/2GKZzppbsikGmokC8ZSagNnXJGmYhNzuRvZPIjY/wybZmHYv X-Received: by 2002:a05:6830:6619:b0:71d:fcb1:f5c3 with SMTP id 46e09a7af769-71e3ba3b5f4mr1955998a34.22.1734109943459; Fri, 13 Dec 2024 09:12:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1734109943; cv=none; d=google.com; s=arc-20240605; b=TCCcCq9Rn4QviIF6fc5UbrNQzg/iHKUhaFXkgWzMQJUwzM1BHn2yo+h2Zg3Iro78YU 5d62IE5aKFjUPuQq2npxoio4q9/qnjIcsTuOqMqeZtaqe0MdTw9WgdMfI/4+aJ4Zmg4d VuvkP2aZgjIeGvDqIh2e0YVJv5QsJgbKUGLkFg2vmMJ+MdpI0GRETdJKg2R8GB+RM424 MLrSmLKy2VL7KmKVixQsIbc3Eg9XvBUCZ+AiodqzlDjjiEjgT5C8ZrA0Kh4KGZsycBrc UxKm/qfuWmWgB/UzoiIIrtkTjUG4LTMSp40C0TfmwAqLZgWxHPBFjkXvcFEzZiyoWD+B JA1A== 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=k2WSK4+XVkTbYcRLTU6iQQfLpBQaFo0vmHk/DkTc8SE=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=GQMAm3d73vETbJy5UQfpK6TaXCH4mC76BZZI932TlVpVhvpvgX/xn+OU8plvvR8KLX NecUjoENKoZH3rNHbAI37EOtEOV5jmDMrlEJojnxopIlTfBhUOeVkm7jWrEQLTwH003G u1vvg880r91xPq6sdElYVEXWzV4veiRjEQUViHVXHlr+fR1zRSQyOrspCw9AXVprfGKt lEoSZGuhrI2yl3ny2s2Zezikv85bav5Lqg2etn+bIfEu0eH2vSNBGK+PAfzgeAsQTG5p uUJlrRXagGThnnoExJmls3AQBoBhZe3GqMXRseCEO1XN9ixyG5A5nernR6vs42CHkqAE vHYQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=mmWUURZf; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=dX+aNtpy; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=dMQVInVv; 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 Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-71dc4a1c6e1si11661560a34.176.2024.12.13.09.12.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Dec 2024 09:12:23 -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=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=mmWUURZf; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=dX+aNtpy; dkim=neutral (body hash did not verify) header.i=@lichtenheld.com header.s=MBO0001 header.b=dMQVInVv; 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 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 1tM9D9-0002l3-Fu; Fri, 13 Dec 2024 17:12:19 +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 1tM9D6-0002kt-HU for openvpn-devel@lists.sourceforge.net; Fri, 13 Dec 2024 17:12:17 +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:Cc:To:From:Sender:Reply-To: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=Nh0ZBR9qwi6wpackvgTL8SC7oaG6E0vOL2nUXd5V+hc=; b=mmWUURZfTo0n0Biao/s9S+CrXD fx3syDehmNe4CbVcUNI2hwt6ofDtSQkljJ8tzUpu5zXYha3pj/4QWV46PiEmv9PRpSaozMHATHOUV TqhfVfeqgj+Wcc1KKEjzdTlLPOAHNb2a7Vi6+2uYHG/2WrWg8tcdGzkMoIXmBN+ugR50=; 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:Cc:To:From:Sender:Reply-To: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=Nh0ZBR9qwi6wpackvgTL8SC7oaG6E0vOL2nUXd5V+hc=; b=dX+aNtpygeKoxixWg8pEqFHS9K wkMucA6P8qqAaV9L1rfgiLZLY1y7ctJ7/kO/6VjJrk59Oi4xzN0onH75MXsqg84/gq3KJexH6Gsba AiTdznco2hBOaZ56rKcjm2BsBTXIZ6pZ1veL0A4G6VnKYh6HDmjHTlFoL6DP/hCKAQgA=; Received: from mout-p-201.mailbox.org ([80.241.56.171]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1tM9D5-0006mi-Ht for openvpn-devel@lists.sourceforge.net; Fri, 13 Dec 2024 17:12:16 +0000 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4Y8wGx2033z9tQ7; Fri, 13 Dec 2024 17:47:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lichtenheld.com; s=MBO0001; t=1734108425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Nh0ZBR9qwi6wpackvgTL8SC7oaG6E0vOL2nUXd5V+hc=; b=dMQVInVvSJav2WXg0FRp3pNACH/7EA1oM9rscUHh4RCZzpIBnncDBUrYkgyl52VYC/GNo6 5vsTHFnekJF9+geR8QN16rwz/atwFDytuLe2NUIpDvm0e5vOOOMtb2/co1GEdi7BhbtZAR J15maFB/JCtSLVSPAsUJozas12JeJgTbXeuetwfzxl7vw8c07WMI2vX1hHkBYNxoobuNOQ YXZzLiXC38nOUghRKkng54C9ZMa5IZChr/psSSGQ4y/bO2t/6Or73nklSsd0cuAvMpraOd xQKY5Mf11KCKH/QqYzK5xQfxNDxem8WPAlQwVOayx2IG59gm18Ff2FmvTBfJeQ== From: Frank Lichtenheld To: openvpn-devel@lists.sourceforge.net Date: Fri, 13 Dec 2024 17:47:04 +0100 Message-Id: <20241213164704.266204-1-frank@lichtenheld.com> In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: -0.9 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", 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: Heiko Hund utf8to16_size() takes the size of the to be converted string. This is needed to convert MULTI_SZ strings, which contain inline NUL characters, but can be useful in other cases as well. Content analysis details: (-0.9 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [80.241.56.171 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [80.241.56.171 listed in bl.score.senderscore.com] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.171 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-Headers-End: 1tM9D5-0006mi-Ht Subject: [Openvpn-devel] [PATCH v1] service: add utf8to16 function that takes a size 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?1818346068420090330?= X-GMAIL-MSGID: =?utf-8?q?1818346068420090330?= From: Heiko Hund utf8to16_size() takes the size of the to be converted string. This is needed to convert MULTI_SZ strings, which contain inline NUL characters, but can be useful in other cases as well. Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b Signed-off-by: Heiko Hund Acked-by: Frank Lichtenheld --- 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/+/836 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Frank Lichtenheld diff --git a/src/openvpnserv/common.c b/src/openvpnserv/common.c index 96bf800..61a7296 100644 --- a/src/openvpnserv/common.c +++ b/src/openvpnserv/common.c @@ -247,17 +247,16 @@ return error; } -/* Convert a utf8 string to utf16. Caller should free the result */ wchar_t * -utf8to16(const char *utf8) +utf8to16_size(const char *utf8, int size) { - int n = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0); + int n = MultiByteToWideChar(CP_UTF8, 0, utf8, size, NULL, 0); wchar_t *utf16 = malloc(n * sizeof(wchar_t)); if (!utf16) { return NULL; } - MultiByteToWideChar(CP_UTF8, 0, utf8, -1, utf16, n); + MultiByteToWideChar(CP_UTF8, 0, utf8, size, utf16, n); return utf16; } diff --git a/src/openvpnserv/service.h b/src/openvpnserv/service.h index 6d0827d..dbb2b5d 100644 --- a/src/openvpnserv/service.h +++ b/src/openvpnserv/service.h @@ -89,8 +89,40 @@ DWORD MsgToEventLog(DWORD flags, LPCTSTR lpszMsg, ...); -/* Convert a utf8 string to utf16. Caller should free the result */ -wchar_t *utf8to16(const char *utf8); +/** + * Convert a UTF-8 string to UTF-16 + * + * The size parameter can be used to convert strings which contain inline NUL + * characters, like MULTI_SZ strings used as values in the registry do, + * or (sub)strings that are not zero terminated. If size is -1 the length + * of the string is determined automatically by the WIN32 API. Make sure + * you pass a terminated string or else bad things will happen. Note that + * the size you pass should always include the terminating zero as well. + * + * If the returned string is not NULL it must be freed by the caller. + * + * @param utf8 const string to be converted + * @param size the size of the string + * + * @return wchar_t* heap allocated result string + */ +wchar_t *utf8to16_size(const char *utf8, int size); + +/** + * Convert a zero terminated UTF-8 string to UTF-16 + * + * This is just a wrapper function that always passes -1 as string size + * to \ref utf8to16_size. + * + * @param utf8 const string to be converted + * + * @return wchar_t* heap allocated result string + */ +inline wchar_t * +utf8to16(const char *utf8) +{ + return utf8to16_size(utf8, -1); +} /* return windows system directory as a pointer to a static string */ const wchar_t *get_win_sys_path(void);