Skip to content

Commit

Permalink
[image] Avoid claiming zero-length images as valid
Browse files Browse the repository at this point in the history
Both the script and PXE images types will claim a zero-length image.
Inhibit this to avoid end-user surprises.
  • Loading branch information
Michael Brown committed Feb 16, 2009
1 parent 076154a commit 24e948f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/arch/i386/image/pxe_image.c
Expand Up @@ -88,6 +88,12 @@ int pxe_load ( struct image *image ) {
if ( filesz > ( 0xa0000 - 0x7c00 ) )
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 */
if ( ! image->type )
image->type = &pxe_image_type;
Expand Down
6 changes: 6 additions & 0 deletions src/image/script.c
Expand Up @@ -94,6 +94,12 @@ static int script_load ( struct image *image ) {
static const char magic[] = "#!gpxe\n";
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 */
copy_from_user ( test, image->data, 0, sizeof ( test ) );
if ( memcmp ( test, magic, sizeof ( test ) ) != 0 ) {
Expand Down

0 comments on commit 24e948f

Please sign in to comment.