Browse Source

[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.
tags/v0.9.7
Michael Brown 15 years ago
parent
commit
24e948f030
2 changed files with 12 additions and 0 deletions
  1. 6
    0
      src/arch/i386/image/pxe_image.c
  2. 6
    0
      src/image/script.c

+ 6
- 0
src/arch/i386/image/pxe_image.c View File

@@ -88,6 +88,12 @@ int pxe_load ( struct image *image ) {
88 88
 	if ( filesz > ( 0xa0000 - 0x7c00 ) )
89 89
 		return -ENOEXEC;
90 90
 
91
+	/* Rejecting zero-length images is also useful, since these
92
+	 * end up looking to the user like bugs in gPXE.
93
+	 */
94
+	if ( ! filesz )
95
+		return -ENOEXEC;
96
+
91 97
 	/* There are no signature checks for PXE; we will accept anything */
92 98
 	if ( ! image->type )
93 99
 		image->type = &pxe_image_type;

+ 6
- 0
src/image/script.c View File

@@ -94,6 +94,12 @@ static int script_load ( struct image *image ) {
94 94
 	static const char magic[] = "#!gpxe\n";
95 95
 	char test[ sizeof ( magic ) - 1 ];
96 96
 
97
+	/* Sanity check */
98
+	if ( image->len < sizeof ( test ) ) {
99
+		DBG ( "Too short to be a script\n" );
100
+		return -ENOEXEC;
101
+	}
102
+
97 103
 	/* Check for magic signature */
98 104
 	copy_from_user ( test, image->data, 0, sizeof ( test ) );
99 105
 	if ( memcmp ( test, magic, sizeof ( test ) ) != 0 ) {

Loading…
Cancel
Save