From c1548908c9e0873c77a59ee647a7dd6bdf833acf Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Thu, 3 Oct 2024 15:08:00 -0600 Subject: [PATCH] NetworkPkg: UefiPxeBcDxe: Fix error packet detection Per RFC 1350, TFTP error packets include 2 byte OpCode and ErrorCode fields in network byte order. Those need to be swapped to host order to be interpreted correctly. Without this change, the TftpErrorReceived and TftpError Mode fields are never set and EFI applications can't inspect the error received from the TFTP server. Signed-off-by: Dan Nicholson --- NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c b/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c index 3ac9c7a8aa..c37bda9d3d 100644 --- a/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c +++ b/NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c @@ -52,12 +52,12 @@ PxeBcMtftp6CheckPacket ( Callback = Private->PxeBcCallback; Status = EFI_SUCCESS; - if (Packet->OpCode == EFI_MTFTP6_OPCODE_ERROR) { + if (NTOHS (Packet->OpCode) == EFI_MTFTP6_OPCODE_ERROR) { // // Store the tftp error message into mode data and set the received flag. // Private->Mode.TftpErrorReceived = TRUE; - Private->Mode.TftpError.ErrorCode = (UINT8)Packet->Error.ErrorCode; + Private->Mode.TftpError.ErrorCode = (UINT8)NTOHS (Packet->Error.ErrorCode); AsciiStrnCpyS ( Private->Mode.TftpError.ErrorString, PXE_MTFTP_ERROR_STRING_LENGTH, @@ -184,7 +184,7 @@ PxeBcMtftp6GetFileSize ( // Store the tftp error message into mode data and set the received flag. // Private->Mode.TftpErrorReceived = TRUE; - Private->Mode.TftpError.ErrorCode = (UINT8)Packet->Error.ErrorCode; + Private->Mode.TftpError.ErrorCode = (UINT8)NTOHS (Packet->Error.ErrorCode); AsciiStrnCpyS ( Private->Mode.TftpError.ErrorString, PXE_MTFTP_ERROR_STRING_LENGTH, @@ -530,12 +530,12 @@ PxeBcMtftp4CheckPacket ( Callback = Private->PxeBcCallback; Status = EFI_SUCCESS; - if (Packet->OpCode == EFI_MTFTP4_OPCODE_ERROR) { + if (NTOHS (Packet->OpCode) == EFI_MTFTP4_OPCODE_ERROR) { // // Store the tftp error message into mode data and set the received flag. // Private->Mode.TftpErrorReceived = TRUE; - Private->Mode.TftpError.ErrorCode = (UINT8)Packet->Error.ErrorCode; + Private->Mode.TftpError.ErrorCode = (UINT8)NTOHS (Packet->Error.ErrorCode); AsciiStrnCpyS ( Private->Mode.TftpError.ErrorString, PXE_MTFTP_ERROR_STRING_LENGTH, @@ -662,7 +662,7 @@ PxeBcMtftp4GetFileSize ( // Store the tftp error message into mode data and set the received flag. // Private->Mode.TftpErrorReceived = TRUE; - Private->Mode.TftpError.ErrorCode = (UINT8)Packet->Error.ErrorCode; + Private->Mode.TftpError.ErrorCode = (UINT8)NTOHS (Packet->Error.ErrorCode); AsciiStrnCpyS ( Private->Mode.TftpError.ErrorString, PXE_MTFTP_ERROR_STRING_LENGTH,