summaryrefslogtreecommitdiffstats
path: root/NetworkPkg
diff options
context:
space:
mode:
authorDan Nicholson <dbn@endlessos.org>2024-10-03 15:08:00 -0600
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2025-01-17 00:32:40 +0000
commitc1548908c9e0873c77a59ee647a7dd6bdf833acf (patch)
treeee387107db88955e5d9be2fdf22b2d00b8a285f3 /NetworkPkg
parentcb672a8eb10ff48b385b53c5fd13e7f175efa94d (diff)
downloadedk2-c1548908c9e0873c77a59ee647a7dd6bdf833acf.tar.gz
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 <dbn@endlessos.org>
Diffstat (limited to 'NetworkPkg')
-rw-r--r--NetworkPkg/UefiPxeBcDxe/PxeBcMtftp.c12
1 files 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,