From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Google-Smtp-Source: AFSGD/WErWKSa2cfQIVB85YxsXLwOYP2YJrQuWUTbO/UgGsXOnw3YF2HocUe7RTxMhyTKchx79RYSQ== 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 Cc: Ard Biesheuvel , Laszlo Ersek , Yonghong Zhu , Liming Gao , Bob Feng , Jaben Carsey 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: [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: , X-List-Received-Date: Fri, 30 Nov 2018 22:45:45 -0000 Content-Transfer-Encoding: 8bit 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(-) 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; } -- 2.19.1