From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.85.128.68; helo=mail-wm1-f68.google.com; envelope-from=philmd@redhat.com; receiver=edk2-devel@lists.01.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) (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 86F5D21195BFD for ; Mon, 3 Dec 2018 02:25:20 -0800 (PST) Received: by mail-wm1-f68.google.com with SMTP id s14so5170048wmh.1 for ; Mon, 03 Dec 2018 02:25:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=mDrlls8LuSyyZcPWYyTb/ZRWcnQRU/kT4YPAuXe7vqA=; b=qcf7kgJm1sfzuhjputRdhNbxKJ8+SMrw5clMXZat2VxMiVlWP/fDT+jRh0y8lyhkx1 K5VqWIx2Gqu2wTG2goYkte9DuYUnazScB2ZuFe+fUUnoNfU+DzoDBlHnQb/h8XclPbVi m74cpl6UWxYiPCjLD6P5pnR25eOaX+lfQsxSnSRiUXog5w6YWX6Nr4EH+a+x8oeCqEoo RFZaSsC0svoJm1gcczoruAMDcL7Hg7zzdSeCEs87jAJI06ZCJJWXWtpSssQa+IaTz6dY xIpM3Rgr6aaonLCPWeo1Xw9/DnV6a0PjhqIB7EcLFn2kil5cK8cni22tkC+Fx31gq4AM LHKg== X-Gm-Message-State: AA+aEWbAu9FeE58+7/F3UoMuasC5FllDdUzcc2cM349ZZw3OV7HYl7N+ lHplCQ4buOpGS1iouCsfM2xorQ== X-Google-Smtp-Source: AFSGD/VAzdPghSEgn+pQbaq6m/ShM++GlH9pqN2x4H2Kdg5OdthmG8p7/jjqmLrDjdvt68uIUQaCCQ== X-Received: by 2002:a1c:a981:: with SMTP id s123mr3735726wme.4.1543832719393; Mon, 03 Dec 2018 02:25:19 -0800 (PST) Received: from ?IPv6:2a01:cb1d:8a0a:f500:48c1:8eab:256a:caf9? ([2a01:cb1d:8a0a:f500:48c1:8eab:256a:caf9]) by smtp.gmail.com with ESMTPSA id f2sm10977263wru.14.2018.12.03.02.25.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 02:25:18 -0800 (PST) To: Ard Biesheuvel , edk2-devel@lists.01.org Cc: Liming Gao , Jaben Carsey , Laszlo Ersek References: <20181130224537.18936-1-ard.biesheuvel@linaro.org> <20181130224537.18936-2-ard.biesheuvel@linaro.org> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Openpgp: id=89C1E78F601EE86C867495CBA2A3FD6EDEADC0DE; url=http://pgp.mit.edu/pks/lookup?op=get&search=0xA2A3FD6EDEADC0DE Message-ID: Date: Mon, 3 Dec 2018 11:25:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <20181130224537.18936-2-ard.biesheuvel@linaro.org> Subject: Re: [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: Mon, 03 Dec 2018 10:25:21 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 30/11/18 23:45, Ard Biesheuvel wrote: > 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 Reviewed-by: Philippe Mathieu-Daudé > --- > 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; > } >