From patchwork Tue Apr 18 14:14:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Selva Nair X-Patchwork-Id: 3192 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:ed0b:b0:ba:3da9:1c4f with SMTP id oy11csp2078683dyb; Tue, 18 Apr 2023 07:15:33 -0700 (PDT) X-Google-Smtp-Source: AKy350YdpHC8R3SfCB/Fyk5lnVGiXTFYcDnp/EtAho2ibOANUdCnfn+rUqpgKvXAjYQH/80AatRf X-Received: by 2002:a92:d209:0:b0:325:b96e:6701 with SMTP id y9-20020a92d209000000b00325b96e6701mr13197727ily.2.1681827333118; Tue, 18 Apr 2023 07:15:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681827333; cv=none; d=google.com; s=arc-20160816; b=rdvr9jY1ZaQBmcUwMxrdSQXDcPrxCeSF71W3V6CEzyhGt1ulBdk5SjdNrVgXcSopOs 6VLlrXTvzjFgRWvjVrPkOYdnE4t6hMcUMUkPXcfqDTVvgye+ZXSb7AeZYxony1uPBATB g4G6UasLRyJMcxDjR14Z9yYL05X6ilYsTjryhWSKIUDAQpwYXv8Xo6mgv+U2+alm1YS9 RrYa0hWq6QraI/LPbuWtFtsiShE0yRJ908Vud+eTBaef041jvGNzu0xTrEEycXvkz44C LzvES5Pf7hMCkfjSMeCEmt3DSghlAMe/Br6yAV1V9iqzVBEKjw8tmujtxMc8bEwkm5vu FzvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=tvTC0FfRbtsmOzdvDXF7v+DxlUkzuQQM7yu5oOcN2hk=; b=rAO149n9aS0MLwOOZkweyFDDQlrEf0pwwDc7pXKBoKZdFL/3q6cmXHKYIVQFrtcpQ0 M/QgE+qDPhF4iWMaJUVe1sua0LC999PPI6SwzCJ8ZSf9DuF7moE9OuBXCYxS7cgRgIJY 70Nc6AqxA/vbmAtNWppMUs3KyDFBBpYGZk7rwDiG4cPqAsIuOOXu6R1Fj4jX2FUKDW49 +04Rq56wYM896080zHRbYWaXXv8R0aTFAbouc9FYq/2Jh7u6uvJdE1c5X6iHJWlcDHRr et1KDU69pjVGOgo06WnuGcpupoMcRJa3I4s4yEep12uvKOTvHcOjvO1j7zzG2oX/Zx06 pGUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=TFURoyKL; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="hSP/iOzu"; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=jLqEN2xR; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id u13-20020a056e02080d00b003264fffb676si8548056ilm.136.2023.04.18.07.15.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2023 07:15:33 -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=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=TFURoyKL; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="hSP/iOzu"; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=jLqEN2xR; 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=QUARANTINE dis=NONE) header.from=gmail.com 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 1pom6z-0004fw-MO; Tue, 18 Apr 2023 14:15:14 +0000 Received: from [172.30.20.202] (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 1pom6z-0004fq-AX for openvpn-devel@lists.sourceforge.net; Tue, 18 Apr 2023 14:15:14 +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=Oi6RkHtXiHE5BMfDTuZkTMZuBQ0Q0BfTWZi3zbwl18k=; b=TFURoyKLQGp82nLVvPIJh1Ivg7 O2LA5Bhuncn0whVuvUwWeWWVycZj8LnEymKhzbNGPXwrC44PHWPsXjkMHabVTNMKW/c+Pjyqu949L VDaDNZCUOjJm1Eb0iAjJXczFTHdJkTlrhO6jDf1f8PuxEqs8DAccM7uzotl4eQYGPhuQ=; 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=Oi6RkHtXiHE5BMfDTuZkTMZuBQ0Q0BfTWZi3zbwl18k=; b=hSP/iOzujibHdxqGYH875SjnDk 3vnRi9DgJ9WUoT/cgLkE1igsUO/4FVlCRWMoiOmd+twNy7dKtT4Z8dva96ErXyoe92vK2X4eXVMX+ +B+gdPl3wUYm84aV7NP9fJYpz7Vf1M/Pmo95mH1PnT/7J4HWOl6/vx9H//vAGRaec/fo=; Received: from mail-yb1-f169.google.com ([209.85.219.169]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1pom6w-0003jk-14 for openvpn-devel@lists.sourceforge.net; Tue, 18 Apr 2023 14:15:14 +0000 Received: by mail-yb1-f169.google.com with SMTP id 3f1490d57ef6-b9242800284so60226276.1 for ; Tue, 18 Apr 2023 07:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681827304; x=1684419304; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Oi6RkHtXiHE5BMfDTuZkTMZuBQ0Q0BfTWZi3zbwl18k=; b=jLqEN2xREihJDDpQR9+xU2YF+8/HS398DkOanX2sbJfWhTaAfKRegOJ7s3hzHb6zpx fRlwa73qMfGii4SvyzFb69APy2EnuIL3n62ajRpESD6zrHi8PSyNsTiDz0qO1SpJ7dO9 WibZDOgCo8uaVNF/sVY3j5t0DYcAg2OCDKDxZOGRXxYx7Ug1D5qj26e6j4JzxZFzbOaX +F4Sgf8XXFG4zbCvVStq6JcdFWy6+Ug4uzp/PFxBmCdMtpd/O2GIAgTihPN50aJ+Of2h yA7ClTVEus93qkgUVBAWB4b2Av/9598mVVsPncgzVW5IZ483iaguMXKRPGJ/fplCy2LG xlJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681827304; x=1684419304; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Oi6RkHtXiHE5BMfDTuZkTMZuBQ0Q0BfTWZi3zbwl18k=; b=ckZGdCQzxJTEPv3rDMesAcpFZ+oKY4r1nDvi8tljwvavrtQO145Ir+Ut/AhEjwOC2n l+1HEKQC5mZpkGljo9X+aWGPZlbB/VQ+EBq/Fc1Fimz6tXQOYKGxKrxrSro+UqoYyAiy faJBxK+EKMsdYlUkYdCoG/pyX1DM1SQMsketSp191JHYLcUny0k4lDtSahPrnFb42JHZ 7iJmSUWxDE1L5uxSlUTTMwt3Z4HtkAyEhybajJ648PV+nR4QREkIPkNXS55TPPKZ6Ily YY7sJa6oRmuTBe5K7c9T3TWuj0yM1eXQRvchP5UmKfEI3dsABHDDoOYD7J4mu1D1Pwjz vByQ== X-Gm-Message-State: AAQBX9cnOZJPQE+zaTX9/GMvOLsc5MBh/fqZ2TETEC6pYwWbpUOV7/5P 2z7HOu8oqafsDXiOeggsiEjbzwJlwhKGIg== X-Received: by 2002:a81:d0f:0:b0:54c:a77:cc7a with SMTP id 15-20020a810d0f000000b0054c0a77cc7amr15189595ywn.1.1681827303891; Tue, 18 Apr 2023 07:15:03 -0700 (PDT) Received: from uranus.sansel.ca (bras-vprn-tnhlon4053w-lp130-01-70-51-222-66.dsl.bell.ca. [70.51.222.66]) by smtp.gmail.com with ESMTPSA id eh6-20020a05690c298600b00552f3887d16sm972787ywb.22.2023.04.18.07.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 07:15:03 -0700 (PDT) From: selva.nair@gmail.com To: openvpn-devel@lists.sourceforge.net Date: Tue, 18 Apr 2023 10:14:46 -0400 Message-Id: <20230418141446.1755363-1-selva.nair@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230418134011.1752777-1-selva.nair@gmail.com> References: <20230418134011.1752777-1-selva.nair@gmail.com> MIME-Version: 1.0 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: From: Selva Nair - We assume that all text passed to the management interface and written to log file are in Unicode (UTF-8). This is broken by the use of the ANSI version of FormatMessage() for Windows error messages [...] Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.219.169 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.219.169 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [selva.nair[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -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.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-Headers-End: 1pom6w-0003jk-14 Subject: [Openvpn-devel] [PATCH v2] Format Windows error message in Unicode 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?1763521596411382266?= X-GMAIL-MSGID: =?utf-8?q?1763523777241535632?= From: Selva Nair - We assume that all text passed to the management interface and written to log file are in Unicode (UTF-8). This is broken by the use of the ANSI version of FormatMessage() for Windows error messages. Fix by using FormatMessageW() and converting the UTF-16 result to UTF-8. v2: assign return value of FormatMessageW() to DWORD, not int Github: fixes OpenVPN/openvpn#319 Signed-off-by: Selva Nair Acked-By: Frank Lichtenheld --- src/openvpn/error.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/openvpn/error.c b/src/openvpn/error.c index a2c9aa4c..9a234e67 100644 --- a/src/openvpn/error.c +++ b/src/openvpn/error.c @@ -970,19 +970,24 @@ strerror_win32(DWORD errnum, struct gc_arena *gc) /* format a windows error message */ { - char message[256]; + wchar_t wmessage[256]; + char *message = NULL; struct buffer out = alloc_buf_gc(256, gc); - const int status = FormatMessage( + const DWORD status = FormatMessageW( FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY, NULL, errnum, 0, - message, - sizeof(message), + wmessage, + SIZE(wmessage), NULL); - if (!status) + if (status) + { + message = utf16to8(wmessage, gc); + } + if (!status || !message) { buf_printf(&out, "[Unknown Win32 Error]"); }