diff options
author | Michael Brown <mcb30@etherboot.org> | 2009-06-03 10:13:29 +0100 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2009-06-03 10:13:29 +0100 |
commit | 4c5f00f8790ccea7c05aa116f580512c854a76a5 (patch) | |
tree | 0a50fba13613fdaecc0dd0b920ffdf1ca4c8b518 /src/image/script.c | |
parent | 5e51aaccaa73d5f6c4e3e5b96938991ac99d1dd6 (diff) | |
download | ipxe-4c5f00f8790ccea7c05aa116f580512c854a76a5.tar.gz |
[script] Allow for DOS-style line endings in scripts
Windows text editors such as Notepad tend to use CRLF line endings,
which breaks gPXE's signature detection for script images. Since
scripts are usually very small, they end up falling back to being
detected as valid PXE executable images (since there are no signature
checks for PXE executables). Executing text files as x86 machine code
tends not to work well.
Fix by allowing for any isspace() character to terminate the "#!gpxe"
signature, and by ensuring that CR characters get stripped during
command line parsing.
Suggested-by: Shao Miller <Shao.Miller@yrdsb.edu.on.ca>
Diffstat (limited to 'src/image/script.c')
-rw-r--r-- | src/image/script.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/image/script.c b/src/image/script.c index e94303abc..0835ecb59 100644 --- a/src/image/script.c +++ b/src/image/script.c @@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <string.h> #include <stdlib.h> +#include <ctype.h> #include <errno.h> #include <gpxe/image.h> @@ -90,8 +91,8 @@ static int script_exec ( struct image *image ) { * @ret rc Return status code */ static int script_load ( struct image *image ) { - static const char magic[] = "#!gpxe\n"; - char test[ sizeof ( magic ) - 1 ]; + static const char magic[] = "#!gpxe"; + char test[ sizeof ( magic ) - 1 /* NUL */ + 1 /* terminating space */]; /* Sanity check */ if ( image->len < sizeof ( test ) ) { @@ -101,7 +102,8 @@ static int script_load ( struct image *image ) { /* Check for magic signature */ copy_from_user ( test, image->data, 0, sizeof ( test ) ); - if ( memcmp ( test, magic, sizeof ( test ) ) != 0 ) { + if ( ( memcmp ( test, magic, ( sizeof ( test ) - 1 ) ) != 0 ) || + ! isspace ( test[ sizeof ( test ) - 1 ] ) ) { DBG ( "Invalid magic signature\n" ); return -ENOEXEC; } |