mirror of
https://github.com/ipxe/ipxe
synced 2025-12-12 23:15:10 +03:00
[efi] Ensure NUL byte is at lowest address within stack cookie
The NUL byte included within the stack cookie to act as a string terminator should be placed at the lowest byte address within the stack cookie, in order to avoid potentially including the stack cookie value within an accidentally unterminated string. Suggested-by: Pete Beck <pete.beck@ioactive.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <endian.h>
|
||||
#include <ipxe/init.h>
|
||||
#include <ipxe/rotate.h>
|
||||
#include <ipxe/efi/efi.h>
|
||||
@@ -128,6 +129,13 @@ efi_stack_cookie ( EFI_HANDLE handle ) {
|
||||
*/
|
||||
cookie <<= 8;
|
||||
|
||||
/* Ensure that the NUL byte is placed at the bottom of the
|
||||
* stack cookie, to avoid potential disclosure via an
|
||||
* unterminated string.
|
||||
*/
|
||||
if ( __BYTE_ORDER == __BIG_ENDIAN )
|
||||
cookie >>= 8;
|
||||
|
||||
return cookie;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user