mirror of
				https://gitlab.com/qemu-project/edk2.git
				synced 2025-10-30 07:56:39 +08:00 
			
		
		
		
	ShellPkg/UefiShellLib: Fix Buffer underflow
Having StrLen(Buffer) == 0 results in a Buffer underflow. Also, StrLen iterates over the Buffer elements until finding a NULL character. This results in a quadratic search for '\r' characters in the while loop. Fix these issues. Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
This commit is contained in:
		 Pierre Gondois
					Pierre Gondois
				
			
				
					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
						
							f242a0e87f
						
					
				
				
					commit
					c2eb2136b4
				
			| @ -4379,6 +4379,7 @@ ShellFileHandleReadLine ( | ||||
| { | ||||
|   EFI_STATUS  Status; | ||||
|   CHAR16      CharBuffer; | ||||
|   UINTN       BufferLength; | ||||
|   UINTN       CharSize; | ||||
|   UINTN       CountSoFar; | ||||
|   UINT64      OriginalFilePosition; | ||||
| @ -4455,8 +4456,9 @@ ShellFileHandleReadLine ( | ||||
|     return (EFI_BUFFER_TOO_SMALL); | ||||
|   } | ||||
|  | ||||
|   while (Buffer[StrLen (Buffer)-1] == L'\r') { | ||||
|     Buffer[StrLen (Buffer)-1] = CHAR_NULL; | ||||
|   BufferLength = StrLen (Buffer); | ||||
|   while ((BufferLength != 0) && (Buffer[--BufferLength] == L'\r')) { | ||||
|     Buffer[BufferLength] = CHAR_NULL; | ||||
|   } | ||||
|  | ||||
|   return (Status); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user