BaseTools/CommonLib: avoid using 'native' word size in IP address handling
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 <ard.biesheuvel@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
		| @@ -1785,7 +1785,7 @@ StrToIpv4Address ( | |||||||
| { | { | ||||||
|   RETURN_STATUS          Status; |   RETURN_STATUS          Status; | ||||||
|   UINTN                  AddressIndex; |   UINTN                  AddressIndex; | ||||||
|   UINTN                  Uintn; |   UINT64                 Uint64; | ||||||
|   EFI_IPv4_ADDRESS       LocalAddress; |   EFI_IPv4_ADDRESS       LocalAddress; | ||||||
|   UINT8                  LocalPrefixLength; |   UINT8                  LocalPrefixLength; | ||||||
|   CHAR16                 *Pointer; |   CHAR16                 *Pointer; | ||||||
| @@ -1812,7 +1812,7 @@ StrToIpv4Address ( | |||||||
|     // |     // | ||||||
|     // Get D or P. |     // Get D or P. | ||||||
|     // |     // | ||||||
|     Status = StrDecimalToUintnS ((CONST CHAR16 *) Pointer, &Pointer, &Uintn); |     Status = StrDecimalToUint64S ((CONST CHAR16 *) Pointer, &Pointer, &Uint64); | ||||||
|     if (RETURN_ERROR (Status)) { |     if (RETURN_ERROR (Status)) { | ||||||
|       return RETURN_UNSUPPORTED; |       return RETURN_UNSUPPORTED; | ||||||
|     } |     } | ||||||
| @@ -1820,18 +1820,18 @@ StrToIpv4Address ( | |||||||
|       // |       // | ||||||
|       // It's P. |       // It's P. | ||||||
|       // |       // | ||||||
|       if (Uintn > 32) { |       if (Uint64 > 32) { | ||||||
|         return RETURN_UNSUPPORTED; |         return RETURN_UNSUPPORTED; | ||||||
|       } |       } | ||||||
|       LocalPrefixLength = (UINT8) Uintn; |       LocalPrefixLength = (UINT8) Uint64; | ||||||
|     } else { |     } else { | ||||||
|       // |       // | ||||||
|       // It's D. |       // It's D. | ||||||
|       // |       // | ||||||
|       if (Uintn > MAX_UINT8) { |       if (Uint64 > MAX_UINT8) { | ||||||
|         return RETURN_UNSUPPORTED; |         return RETURN_UNSUPPORTED; | ||||||
|       } |       } | ||||||
|       LocalAddress.Addr[AddressIndex] = (UINT8) Uintn; |       LocalAddress.Addr[AddressIndex] = (UINT8) Uint64; | ||||||
|       AddressIndex++; |       AddressIndex++; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -1888,7 +1888,7 @@ StrToIpv6Address ( | |||||||
| { | { | ||||||
|   RETURN_STATUS          Status; |   RETURN_STATUS          Status; | ||||||
|   UINTN                  AddressIndex; |   UINTN                  AddressIndex; | ||||||
|   UINTN                  Uintn; |   UINT64                 Uint64; | ||||||
|   EFI_IPv6_ADDRESS       LocalAddress; |   EFI_IPv6_ADDRESS       LocalAddress; | ||||||
|   UINT8                  LocalPrefixLength; |   UINT8                  LocalPrefixLength; | ||||||
|   CONST CHAR16           *Pointer; |   CONST CHAR16           *Pointer; | ||||||
| @@ -1969,7 +1969,7 @@ StrToIpv6Address ( | |||||||
|         // |         // | ||||||
|         // Get X. |         // Get X. | ||||||
|         // |         // | ||||||
|         Status = StrHexToUintnS (Pointer, &End, &Uintn); |         Status = StrHexToUint64S (Pointer, &End, &Uint64); | ||||||
|         if (RETURN_ERROR (Status) || End - Pointer > 4) { |         if (RETURN_ERROR (Status) || End - Pointer > 4) { | ||||||
|           // |           // | ||||||
|           // Number of hexadecimal digit characters is no more than 4. |           // Number of hexadecimal digit characters is no more than 4. | ||||||
| @@ -1978,24 +1978,24 @@ StrToIpv6Address ( | |||||||
|         } |         } | ||||||
|         Pointer = End; |         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)); |         ASSERT (AddressIndex + 1 < ARRAY_SIZE (Address->Addr)); | ||||||
|         LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uintn >> 8); |         LocalAddress.Addr[AddressIndex] = (UINT8) ((UINT16) Uint64 >> 8); | ||||||
|         LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uintn; |         LocalAddress.Addr[AddressIndex + 1] = (UINT8) Uint64; | ||||||
|         AddressIndex += 2; |         AddressIndex += 2; | ||||||
|       } else { |       } else { | ||||||
|         // |         // | ||||||
|         // Get P, then exit the loop. |         // Get P, then exit the loop. | ||||||
|         // |         // | ||||||
|         Status = StrDecimalToUintnS (Pointer, &End, &Uintn); |         Status = StrDecimalToUint64S (Pointer, &End, &Uint64); | ||||||
|         if (RETURN_ERROR (Status) || End == Pointer || Uintn > 128) { |         if (RETURN_ERROR (Status) || End == Pointer || Uint64 > 128) { | ||||||
|           // |           // | ||||||
|           // Prefix length should not exceed 128. |           // Prefix length should not exceed 128. | ||||||
|           // |           // | ||||||
|           return RETURN_UNSUPPORTED; |           return RETURN_UNSUPPORTED; | ||||||
|         } |         } | ||||||
|         LocalPrefixLength = (UINT8) Uintn; |         LocalPrefixLength = (UINT8) Uint64; | ||||||
|         Pointer = End; |         Pointer = End; | ||||||
|         break; |         break; | ||||||
|       } |       } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user