From patchwork Thu Dec 12 07:47:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "ralf_lici (Code Review)" X-Patchwork-Id: 3989 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:750c:b0:5e7:b9eb:58e8 with SMTP id r12csp1399778mai; Wed, 11 Dec 2024 23:48:03 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCW9rXLEfMZBxXoiXMRwepki5R1onR0HBoO8tHj57H5QKY/oWrZTeaFep0DMjfvuddQT1X2xMOYO3KA=@openvpn.net X-Google-Smtp-Source: AGHT+IHw5cYpm0EZuhBw+KXBWQtV06mVa9JNgp2O0otXdM+EHuCG69G0rp0NmKLyNdkCyeWnM2Xb X-Received: by 2002:a05:6870:170a:b0:295:ed0a:8061 with SMTP id 586e51a60fabf-2a38278a461mr1537324fac.39.1733989682879; Wed, 11 Dec 2024 23:48:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1733989682; cv=none; d=google.com; s=arc-20240605; b=Rt3vhHGBFRSA5bzyNMUDTsvhUDqdTAH/UjnhAm7+X+Sr0R4U0B8axqKVNnkA3mR+1J NjiuEDC5ooCBU4voOD3M1h5cJwelvI1HyGOBrKUYw1YMJeTONEp2t+u6x6Qpd2BdLVHp eJVZC7SmLtSQhHcM2FpFFUnBnn9v/STxMD6YhlM4cWCh7rGiSDevQxwcCFC219obJFi9 xE2vRSFfSjXoG26sainkD9By+0gAWMfk5+awfKXM5KjqfeVhLnLqPTe2SKezuUgLZGGA tvFkrAkMx2175/r5PZ849SKBqZiJdwKjO1v0w52Ia2qGFMpyg5k8i6IdKLwGc+Ua/Wh+ 4U4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:user-agent :mime-version:message-id:references:auto-submitted:to:date:from :dkim-signature:dkim-signature:dkim-signature; bh=yxTZS8/LhmUNc5pk9WaVEds0w/AOGnYw//44H9VX6/I=; fh=U7wEyxtwz2o5+UdevFSA47vNeG9knhWH0KV//QhD5a0=; b=Yw49941ZuKDDpNVVwCEjft/j6+pWc8wNNjDvM9mHF9O5nUQAtDdkxikRwQC+ceGux+ BlEPIbfA1kELgs91/OlwHPGnnOqV68IuG45S1fFEDicj4IYYTNKM4cntQRZkHSpUSXrz plrT/3uebMSt81h+sqycrRCGQgqEfUS4LAu1GKVAVok+wuvnIZwNdKJPE/MRgM0Nai0V CTq5xMgznA8N6//uEkxtSzsoTc/Gja+6/YgWjUvT/+bvIh/14TPuwrKpdjeYZnTPIEiS lq6o9LTzqnKM0Us0zvoe4hhZHYhN+qR3gRyowvxZuSaM1UCr4kDBMIqt+7NPBx17//ek bs8Q==; 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=aBAy6bTa; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=aOu3hQDN; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=M2AHWoXd; 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=openvpn.net; dara=fail header.i=@openvpn.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 586e51a60fabf-29f569c5fc4si7803768fac.272.2024.12.11.23.48.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Dec 2024 23:48:02 -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=aBAy6bTa; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=aOu3hQDN; dkim=neutral (body hash did not verify) header.i=@openvpn.net header.s=google header.b=M2AHWoXd; 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=openvpn.net; dara=fail header.i=@openvpn.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tLdvS-0001ii-Uw; Thu, 12 Dec 2024 07:47:58 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tLdvR-0001iQ-Ow for openvpn-devel@lists.sourceforge.net; Thu, 12 Dec 2024 07:47:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:Content-Transfer-Encoding:MIME-Version :Message-ID:Reply-To:References:Subject:List-Unsubscribe:List-Id:Cc:To:Date: From:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help: List-Subscribe:List-Post:List-Owner:List-Archive; bh=BQnfDm6pE3XywT84MW/I8Y01ASLygQWsCikSHvifrd0=; b=aBAy6bTaGRKo1VhekQAOh6jE7P JSS12kggCAt/P4lIPsR6OUjOSu2qfCcj0PO/fpC7MPcpOjVg37F3WGmVmi3FS2tgsXPPCp4NaShNY dEpMQFreLeMi6Dv15Rx5p+uAfJfoL69K5ZwX9A0JO8/u5o4PeoZFUSQIzBZecltUWw08=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Reply-To: References:Subject:List-Unsubscribe:List-Id:Cc:To:Date:From:Sender:Content-ID :Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:In-Reply-To:List-Help:List-Subscribe:List-Post: List-Owner:List-Archive; bh=BQnfDm6pE3XywT84MW/I8Y01ASLygQWsCikSHvifrd0=; b=a Ou3hQDNPcdRpud73VJarX05YBlUvoMYL5zQUcA7hsqyjga9p+M07Vga+9Gous341txVasmDbaE9IE 7M+g/qA9f/GFbJnYrav5q1wJ4rUXFzu3EAfF32fnfi9CpFk8PETIzmNt3ogd/A532VXEm943lDXGr paO282C9VktPL+C0=; Received: from mail-wr1-f54.google.com ([209.85.221.54]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1tLdvQ-00064V-BX for openvpn-devel@lists.sourceforge.net; Thu, 12 Dec 2024 07:47:57 +0000 Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-385de9f789cso191633f8f.2 for ; Wed, 11 Dec 2024 23:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1733989665; x=1734594465; darn=lists.sourceforge.net; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from:from:to:cc :subject:date:message-id:reply-to; bh=BQnfDm6pE3XywT84MW/I8Y01ASLygQWsCikSHvifrd0=; b=M2AHWoXdrKqqvAe3p1nIWkb3kTiOHR/XZi/5LTuY6NHVSSEt7hrHb1np6sYovtWK4N /1j4GZLKkqjf8wQqXZTIB5ikd7/T2hF3/m9aX5advNIWMV+AzRT+4DWM+PX3SaTSfXvg Zs74ng5AexfAuY1zux5FREjWuq6JxVnuOg1FIUB7P9uBom+5gPZIQwaEmZVQ7QvsfekZ V1jHe40lpax3oawZQTMatIH+jYuHan6ol/v0WrCxtEmUnYBpQ+E649nk7OPKa2RbvZnA OenYQGBm8Hv63HeGohYDWcpxUPtSnfJoemUikw4xubJADUxZQd8O07QmoLFPF1TN2fJ4 j4KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733989665; x=1734594465; h=user-agent:content-disposition:content-transfer-encoding :mime-version:message-id:reply-to:references:subject :list-unsubscribe:list-id:auto-submitted:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BQnfDm6pE3XywT84MW/I8Y01ASLygQWsCikSHvifrd0=; b=lfhUJmfiJAdZjwq/oBpVrBfRwlN/87CxwEG5/cJJRnYjnFXxKqMOUOLpOwc2jHFWZy d9c1FLOcakYa3VdgWNokBsBbHZEHMPFi0iI8c9eTTgKGaBj3z0pbUnbo0/Ahk/AXB6As satZRgNVzvFHi+QUzlLefBi4YDml0detLWEu9NrDuYvqeOArGf9hklN3NOm3hVseYAhe ObkSfAteAeBEmpT9GP2sp3sIAvdK/ZCwTlYcAlUfN072QdRd+qkFTlkp+B3lp8K04Vzq r69BLMKEVNWNNCYfuyxZpxY1yH+vzWy3iH75aVuAxWOz7syeZWmwSua9o9ft4RK4KMVz vbMw== X-Gm-Message-State: AOJu0Yy2DS5X5VX3ToJnGJrTswYt1rT9Lxi4nRhxsa/LLaXeLSC5JP/l G8sUEbosV0GmsVNTUS06St8Q4SCoBQfpc840WuUdSSW+5H97hu0Fi4FTnChZ8nRTNlPINJkJFPd H X-Gm-Gg: ASbGncvBS5MY3ruqrn0N35p1Sz7aHM/v/tmTGN3yeMYI4gmATA6ZfC3UQYy/DoZIQAn 8OKgxdiUzroNGt5UWwG9ZEI/twU3oWhBZFY/cc2PXwqXTJJq12W9Qdlbt1Dk9QRf1BzGenSBwF4 9+wv2OXq5NM93/nsoOw50nM7xnPfu4fLK+dME9KMfLT1HoVN1lG2AIHiPLW2BUPE2eVku0jJyUu 6Le/t5Gza9j/S5entvs+GRiM7ISyMJtADUt3K5hz8IV+sNQVLu6V5TgV0E4nmT8d+bVJKnOYwJI eaN/Lo9aRj9Gmna2TH/I77h6ObfuDBb0emC6tYrrR98N4nO8 X-Received: by 2002:a05:6000:1543:b0:386:1cd3:8a08 with SMTP id ffacd0b85a97d-38787685025mr2082872f8f.5.1733989664830; Wed, 11 Dec 2024 23:47:44 -0800 (PST) Received: from gerrit.openvpn.in (ec2-18-159-0-78.eu-central-1.compute.amazonaws.com. [18.159.0.78]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-387825266besm3185616f8f.108.2024.12.11.23.47.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 23:47:44 -0800 (PST) From: "d12fk (Code Review)" X-Google-Original-From: "d12fk (Code Review)" X-Gerrit-PatchSet: 1 Date: Thu, 12 Dec 2024 07:47:43 +0000 To: plaisthos , flichtenheld Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange X-Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b X-Gerrit-Change-Number: 836 X-Gerrit-Project: openvpn X-Gerrit-ChangeURL: X-Gerrit-Commit: d3f083a60b33a44af0613899ad4654073b4277d1 References: Message-ID: MIME-Version: 1.0 User-Agent: Gerrit/3.8.2 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-1.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: Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [209.85.221.54 listed in sa-accredit.habeas.com] 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. [209.85.221.54 listed in bl.score.senderscore.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.221.54 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.221.54 listed in list.dnswl.org] 0.0 WEIRD_PORT URI: Uses non-standard port number for HTTP 0.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 T_KAM_HTML_FONT_INVALID Test for Invalidly Named or Formatted Colors in HTML X-Headers-End: 1tLdvQ-00064V-BX Subject: [Openvpn-devel] [S] Change in openvpn[master]: 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: , Reply-To: heiko@openvpn.net, arne-openvpn@rfc2549.org, openvpn-devel@lists.sourceforge.net, frank@lichtenheld.com Cc: openvpn-devel Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1818219965989642694?= X-GMAIL-MSGID: =?utf-8?q?1818219965989642694?= X-getmail-filter-classifier: gerrit message type newchange Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/836?usp=email to review the following change. Change subject: service: add utf8to16 function that takes a size ...................................................................... service: add utf8to16 function that takes a size 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 --- M src/openvpnserv/common.c M src/openvpnserv/service.h 2 files changed, 37 insertions(+), 6 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/836/1 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);