mirror of
https://github.com/ipxe/ipxe
synced 2025-12-18 02:20:19 +03:00
[image] Avoid claiming zero-length images as valid
Both the script and PXE images types will claim a zero-length image. Inhibit this to avoid end-user surprises.
This commit is contained in:
@@ -88,6 +88,12 @@ int pxe_load ( struct image *image ) {
|
|||||||
if ( filesz > ( 0xa0000 - 0x7c00 ) )
|
if ( filesz > ( 0xa0000 - 0x7c00 ) )
|
||||||
return -ENOEXEC;
|
return -ENOEXEC;
|
||||||
|
|
||||||
|
/* Rejecting zero-length images is also useful, since these
|
||||||
|
* end up looking to the user like bugs in gPXE.
|
||||||
|
*/
|
||||||
|
if ( ! filesz )
|
||||||
|
return -ENOEXEC;
|
||||||
|
|
||||||
/* There are no signature checks for PXE; we will accept anything */
|
/* There are no signature checks for PXE; we will accept anything */
|
||||||
if ( ! image->type )
|
if ( ! image->type )
|
||||||
image->type = &pxe_image_type;
|
image->type = &pxe_image_type;
|
||||||
|
|||||||
@@ -94,6 +94,12 @@ static int script_load ( struct image *image ) {
|
|||||||
static const char magic[] = "#!gpxe\n";
|
static const char magic[] = "#!gpxe\n";
|
||||||
char test[ sizeof ( magic ) - 1 ];
|
char test[ sizeof ( magic ) - 1 ];
|
||||||
|
|
||||||
|
/* Sanity check */
|
||||||
|
if ( image->len < sizeof ( test ) ) {
|
||||||
|
DBG ( "Too short to be a script\n" );
|
||||||
|
return -ENOEXEC;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check for magic signature */
|
/* Check for magic signature */
|
||||||
copy_from_user ( test, image->data, 0, sizeof ( test ) );
|
copy_from_user ( test, image->data, 0, sizeof ( test ) );
|
||||||
if ( memcmp ( test, magic, sizeof ( test ) ) != 0 ) {
|
if ( memcmp ( test, magic, sizeof ( test ) ) != 0 ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user