diff options
| author | Simon Rettberg | 2026-01-28 12:53:53 +0100 |
|---|---|---|
| committer | Simon Rettberg | 2026-01-28 12:53:53 +0100 |
| commit | 8e82785c584dc13e20f9229decb95bd17bbe9cd1 (patch) | |
| tree | a8b359e59196be5b2e3862bed189107f4bc9975f /src/image/script.c | |
| parent | Merge branch 'master' into openslx (diff) | |
| parent | [prefix] Make unlzma.S compatible with 386 class CPUs (diff) | |
| download | ipxe-openslx.tar.gz ipxe-openslx.tar.xz ipxe-openslx.zip | |
Merge branch 'master' into openslxopenslx
Diffstat (limited to 'src/image/script.c')
| -rw-r--r-- | src/image/script.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/image/script.c b/src/image/script.c index 9e8566bc5..57662b788 100644 --- a/src/image/script.c +++ b/src/image/script.c @@ -22,6 +22,7 @@ */ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +FILE_SECBOOT ( PERMITTED ); /** * @file @@ -69,7 +70,7 @@ static int process_script ( struct image *image, size_t line_offset; char *label; char *command; - off_t eol; + const void *eol; size_t frag_len; char *tmp; int rc; @@ -81,11 +82,13 @@ static int process_script ( struct image *image, do { /* Find length of next line, excluding any terminating '\n' */ - eol = memchr_user ( image->data, script_offset, '\n', - ( image->len - script_offset ) ); - if ( eol < 0 ) - eol = image->len; - frag_len = ( eol - script_offset ); + eol = memchr ( ( image->data + script_offset ), '\n', + ( image->len - script_offset ) ); + if ( eol ) { + frag_len = ( ( eol - image->data ) - script_offset ); + } else { + frag_len = ( image->len - script_offset ); + } /* Allocate buffer for line */ tmp = realloc ( line, ( len + frag_len + 1 /* NUL */ ) ); @@ -96,8 +99,8 @@ static int process_script ( struct image *image, line = tmp; /* Copy line */ - copy_from_user ( ( line + len ), image->data, script_offset, - frag_len ); + memcpy ( ( line + len ), ( image->data + script_offset ), + frag_len ); len += frag_len; /* Move to next line in script */ @@ -220,20 +223,24 @@ static int script_probe ( struct image *image ) { static const char ipxe_magic[] = "#!ipxe"; static const char gpxe_magic[] = "#!gpxe"; static_assert ( sizeof ( ipxe_magic ) == sizeof ( gpxe_magic ) ); - char test[ sizeof ( ipxe_magic ) - 1 /* NUL */ - + 1 /* terminating space */]; + const struct { + char magic[ sizeof ( ipxe_magic ) - 1 /* NUL */ ]; + char space; + } __attribute__ (( packed )) *test; /* Sanity check */ - if ( image->len < sizeof ( test ) ) { + if ( image->len < sizeof ( *test ) ) { DBGC ( image, "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, ipxe_magic, sizeof ( test ) - 1 ) == 0 ) || - ( memcmp ( test, gpxe_magic, sizeof ( test ) - 1 ) == 0 )) && - isspace ( test[ sizeof ( test ) - 1 ] ) ) ) { + test = image->data; + if ( ! ( ( ( memcmp ( test->magic, ipxe_magic, + sizeof ( test->magic ) ) == 0 ) || + ( memcmp ( test->magic, gpxe_magic, + sizeof ( test->magic ) ) == 0 ) ) && + isspace ( test->space ) ) ) { DBGC ( image, "Invalid magic signature\n" ); return -ENOEXEC; } @@ -346,10 +353,7 @@ static int goto_exec ( int argc, char **argv ) { } /** "goto" command */ -struct command goto_command __command = { - .name = "goto", - .exec = goto_exec, -}; +COMMAND ( goto, goto_exec ); /** "prompt" options */ struct prompt_options { @@ -412,7 +416,4 @@ static int prompt_exec ( int argc, char **argv ) { } /** "prompt" command */ -struct command prompt_command __command = { - .name = "prompt", - .exec = prompt_exec, -}; +COMMAND ( prompt, prompt_exec ); |
