Skip to content

Commit

Permalink
NetworkPkg: UefiPxeBcDxe: Fix error packet detection
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dbnicholson authored and mdkinney committed Jan 16, 2025
1 parent b24ad97 commit 16d213d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 16d213d

Please sign in to comment.