From 4c5f00f8790ccea7c05aa116f580512c854a76a5 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 3 Jun 2009 10:13:29 +0100 Subject: [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 --- src/image/script.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/image') 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 #include +#include #include #include @@ -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; } -- cgit v1.2.3-55-g7522