mirror of
				https://gitlab.com/qemu-project/edk2.git
				synced 2025-10-30 07:56:39 +08:00 
			
		
		
		
	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>
This commit is contained in:
		 Dan Nicholson
					Dan Nicholson
				
			
				
					committed by
					
						![mergify[bot]](/assets/img/avatar_default.png) mergify[bot]
						mergify[bot]
					
				
			
			
				
	
			
			
			![mergify[bot]](/assets/img/avatar_default.png) mergify[bot]
						mergify[bot]
					
				
			
						parent
						
							cb672a8eb1
						
					
				
				
					commit
					c1548908c9
				
			| @ -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, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user