From patchwork Fri Nov 30 22:45:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 152609 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4211845ljp; Fri, 30 Nov 2018 14:45:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/UVV8HhPRv28dFFPFRt/qMfZEpsxFWUJtaOCo+S0y8tfqt1xayLQKTKbG7rTvv3m5qXFfr/ X-Received: by 2002:aa7:8552:: with SMTP id y18mr7472864pfn.83.1543617948183; Fri, 30 Nov 2018 14:45:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543617948; cv=none; d=google.com; s=arc-20160816; b=Yuyj7HOb8jQl3Lagjhcxs+89yL1Ewzfzh/0uttUvAJxXOw0DxeANyxCzz3b/Ovte9t 2pFbiXB2YMZTl0xqJwUf8S4gU+CP1L8XXaZKYlazOCLslwtOipTTY2imWlxDVT+sSOzq vJ5hZFX5aGP08dUDUGCGjVzLPRK2BBPi9ehyHlJIc/ndJ9IB+dBeWBKH/yB+UVd6aGT1 szPk912fPlHlTKMMbLSAbWu8elfuuBW1D7DVCStBJS1nyPdW9DrXObhyh+Z4egRaRhHa hz1N06qbQcsIm8nBpTUzjhM9uXsFSqAnYEAQNxoyrMfv364ue+dCxzPOU8cRx1fWSYoJ fh8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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:delivered-to; bh=A0Mhn5jzUiD4mP3RYZx4M4TFkKiqglfzyiKL5pMvkRY=; b=v7Mdila5OdyGHK5Zw4W2FPXPLci1rDTC70RRIe8lL3r2h2VsijEtgRJaAdXsYi4kKz kk3W8jdUwOUQ7uDGNaCA+IlAhWinjaGZ/6ow/v0uJ5WIMxZ8awZ7XWxi+amx+Ha9DinT XePvne1mo73SWnXA3DixbxnxaBUrA6HNU9OYmZ2IPWv6iGkL2j3BnD29YjJBkLbKsqev 8KGLWDlVdPR+F6syBw2dzQXe4nmbVlj9tgoGB/Yfu0GBAXXwtAwJK7yybyQWVBp4wFTe mf2bVLjlGugrYb7EXlOzD8QUigJRp4U3SD/xUxqx2MEwcgSK9NhE+Joeucvlt74ZtUxT IzGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Orblfly2; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id f63si6064370pgc.473.2018.11.30.14.45.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 14:45:48 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Orblfly2; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6EC1B21BADAB9; Fri, 30 Nov 2018 14:45:46 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::341; helo=mail-wm1-x341.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BDFD8211963D9 for ; Fri, 30 Nov 2018 14:45:44 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id y1so445349wmi.3 for ; Fri, 30 Nov 2018 14:45:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gJ6apygiqYrhZFv1h43rGB8h3gUD5pOIeKAE9HDRrAE=; b=Orblfly2LZftQFpLnEWQ3JZCPIESegC/BQq+Gz9DUSVrWZ91+b3rwpSuF6LTRrSnmf 5CBgVum6YrylG3eYEHlF7e/6Fz49ywv6/sbXydU/G8aJ1xmVxqIB9e1tw777vULo2TR6 lw/DnacrsTB+cOHbQ1U2L48DI5bC7VbLv0PKY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gJ6apygiqYrhZFv1h43rGB8h3gUD5pOIeKAE9HDRrAE=; b=ZCre7XQRaWdiAYs4ooweqHQN6sq1npoD0y/qt3uYCeeSXsgLngHjBfat/pXb/qQya+ 7IiayeKBV7vNs0ltV/SrGdOLrOmKndMrzhUfc3XsbJEJB3xAdQvOhrLUYtGw3sTxe4gV 54T7u1NsyNFrMjx7j4RtwTLxjDoewmkwaf9SOeMyxtqNqOpCFEs0nN1nijJY9uEySzRc krigB5WYFrcejBqU9BqBx0BjBXB5bcMpSf1P4OezF8dGJOW0oDOgocfwtV6V8RIFCSgy 7I6n2+oqutwIJKZRVURVRPRYqtG570b+0KnilghyQnTrcqdlLtJ/S6uo9F6KCRV/I9C8 y1cA== X-Gm-Message-State: AA+aEWYfoWd0h7FLT2/dOxEcnxUBs71ix4B6M1MDFn2+Hw6g/DX3tWHW mNb+b//T9Shjyi9+5bFMFNCHQwHRPjk= X-Received: by 2002:a1c:bd82:: with SMTP id n124mr476151wmf.105.1543617942845; Fri, 30 Nov 2018 14:45:42 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:d895:e032:7b00:86cd]) by smtp.gmail.com with ESMTPSA id m6sm10561195wrv.24.2018.11.30.14.45.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 14:45:41 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Fri, 30 Nov 2018 23:45:32 +0100 Message-Id: <20181130224537.18936-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181130224537.18936-1-ard.biesheuvel@linaro.org> References: <20181130224537.18936-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Subject: [edk2] [PATCH v2 1/6] BaseTools/CommonLib: avoid using 'native' word size in IP address handling X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Liming Gao , Jaben Carsey , Laszlo Ersek Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" In the context of the BaseTools, there is no such thing as a native word size, given that the same set of tools may be used to build a firmware image consisting of both 32-bit and 64-bit modules. So update StrToIpv4Address() and StrToIpv6Address() to use UINT64 types instead of UINTN types when parsing strings. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- BaseTools/Source/C/Common/CommonLib.c | 28 ++++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) -- 2.19.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Laszlo Ersek diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Common/CommonLib.c index 618aadac781a..7c559bc3c222 100644 --- a/BaseTools/Source/C/Common/CommonLib.c +++ b/BaseTools/Source/C/Common/CommonLib.c @@ -1785,7 +1785,7 @@ StrToIpv4Address ( { RETURN_STATUS Status; UINTN AddressIndex; - UINTN Uintn; + UINT64 Uint64; EFI_IPv4_ADDRESS LocalAddress; UINT8 LocalPrefixLength; CHAR16 *Pointer; @@ -1812,7 +1812,7 @@ StrToIpv4Address ( // // Get D or P. // - Status = StrDecimalToUintnS ((CONST CHAR16 *) Pointer, &Pointer, &Uintn); + Status = StrDecimalToUint64S ((CONST CHAR16 *) Pointer, &Pointer, &Uint64); if (RETURN_ERROR (Status)) { return RETURN_UNSUPPORTED; } @@ -1820,18 +1820,18 @@ StrToIpv4Address ( // // It's P. // - if (Uintn > 32) { + if (Uint64 > 32) { return RETURN_UNSUPPORTED; } - LocalPrefixLength = (UINT8) Uintn; + LocalPrefixLength = (UINT8) Uint64; } else { // // It's D. // - if (Uintn > MAX_UINT8) { + if (Uint64 > MAX_UINT8) { return RETURN_UNSUPPORTED; } - LocalAddress.Addr[AddressIndex] = (UINT8) Uintn; + LocalAddress.Addr[AddressIndex] = (UINT8) Uint64; AddressIndex++; } @@ -1888,7 +1888,7 @@ StrToIpv6Address ( { RETURN_STATUS Status; UINTN AddressIndex; - UINTN Uintn; + UINT64 Uint64; EFI_IPv6_ADDRESS LocalAddress; UINT8 LocalPrefixLength; CONST CHAR16 *Pointer; @@ -1969,7 +1969,7 @@ StrToIpv6Address ( // // Get X. // - Status = StrHexToUintnS (Pointer, &End, &Uintn); + Status = StrHexToUint64S (Pointer, &End, &Uint64); if (RETURN_ERROR (Status) || End - Pointer > 4) { // // Number of hexadecimal digit characters is no more than 4. @@ -1978,24 +1978,24 @@ StrToIpv6Address ( } Pointer = End; // - // Uintn won't exceed MAX_UINT16 if number of hexadecimal digit characters is no more than 4. + // Uint64 won't exceed MAX_UINT16 if number of hexadecimal digit characters is no more than 4. // ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr)); - LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uintn >> 8); - LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uintn; + LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uint64 >> 8); + LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uint64; AddressIndex += 2; } else { // // Get P, then exit the loop. // - Status = StrDecimalToUintnS (Pointer, &End, &Uintn); - if (RETURN_ERROR (Status) || End == Pointer || Uintn > 128) { + Status = StrDecimalToUint64S (Pointer, &End, &Uint64); + if (RETURN_ERROR (Status) || End == Pointer || Uint64 > 128) { // // Prefix length should not exceed 128. // return RETURN_UNSUPPORTED; } - LocalPrefixLength = (UINT8) Uintn; + LocalPrefixLength = (UINT8) Uint64; Pointer = End; break; }