From f96efb2df378aea66d5e18f5adc1f9e0b47615d0 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 28 Feb 2005 05:44:52 +0000 Subject: [PATCH] Allow the #! command line to be up to PAGE_SIZE long, rather then artificially limiting it to MAXSHELLCMDLEN. The interpreter name is still limited to MAXSHELLCMDLEN. A \0 is now considered a line terminator. Correctly report the ENAMETOOLONG case. Note that FreeBSD (and hence DragonFly) break the #! line into multiple argv arguments, which is not what any other UNIX does. This is likely going to be changed in the future but not as of this commit. Inspired-by: Maxim Sobolev / similar FreeBSD work, and Garance A Drosihn --- sys/kern/imgact_shell.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/sys/kern/imgact_shell.c b/sys/kern/imgact_shell.c index a0358c53f5..60a81621ce 100644 --- a/sys/kern/imgact_shell.c +++ b/sys/kern/imgact_shell.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/imgact_shell.c,v 1.21.2.2 2001/12/22 01:21:39 jwd Exp $ - * $DragonFly: src/sys/kern/imgact_shell.c,v 1.5 2005/02/25 08:49:10 dillon Exp $ + * $DragonFly: src/sys/kern/imgact_shell.c,v 1.6 2005/02/28 05:44:52 dillon Exp $ */ #include @@ -71,7 +71,7 @@ exec_shell_imgact(struct image_params *imgp) */ ihp = &image_header[2]; offset = 0; - while (ihp < &image_header[MAXSHELLCMDLEN]) { + while (ihp < &image_header[PAGE_SIZE]) { /* Skip any whitespace */ if (*ihp == ' ' || *ihp == '\t') { ++ihp; @@ -79,16 +79,16 @@ exec_shell_imgact(struct image_params *imgp) } /* End of line? */ - if (*ihp == '\n' || *ihp == '#') + if (*ihp == '\n' || *ihp == '#' || *ihp == '\0') break; /* Found a token */ do { ++offset; ++ihp; - } while (ihp < &image_header[MAXSHELLCMDLEN] && + } while (ihp < &image_header[PAGE_SIZE] && *ihp != ' ' && *ihp != '\t' && - *ihp != '\n' && *ihp != '#'); + *ihp != '\n' && *ihp != '#' && *ihp != '\0'); /* Take into account the \0 that will terminate the token */ ++offset; @@ -98,8 +98,12 @@ exec_shell_imgact(struct image_params *imgp) if (offset == 0) return (ENOEXEC); - /* It should not be possible for offset to exceed MAXSHELLCMDLEN */ - KKASSERT(offset <= MAXSHELLCMDLEN); + /* It should not be possible for offset to exceed PAGE_SIZE */ + KKASSERT(offset <= PAGE_SIZE); + + /* Check that we aren't too big */ + if (ihp == &image_header[PAGE_SIZE]) + return (ENAMETOOLONG); /* * The full path name of the original script file must be tagged @@ -130,15 +134,15 @@ exec_shell_imgact(struct image_params *imgp) */ ihp = &image_header[2]; offset = 0; - while (ihp < &image_header[MAXSHELLCMDLEN]) { + while (ihp < &image_header[PAGE_SIZE]) { /* Skip whitespace */ - if ((*ihp == ' ' || *ihp == '\t')) { + if (*ihp == ' ' || *ihp == '\t') { ++ihp; continue; } /* End of line? */ - if ((*ihp == '\n') || (*ihp == '#')) + if (*ihp == '\n' || *ihp == '#' || *ihp == '\0') break; /* Found a token, copy it */ @@ -146,9 +150,9 @@ exec_shell_imgact(struct image_params *imgp) imgp->args->begin_argv[offset] = *ihp; ++ihp; ++offset; - } while (ihp < &image_header[MAXSHELLCMDLEN] && + } while (ihp < &image_header[PAGE_SIZE] && *ihp != ' ' && *ihp != '\t' && - *ihp != '\n' && *ihp != '#'); + *ihp != '\n' && *ihp != '#' && *ihp != '\0'); /* And terminate the argument */ imgp->args->begin_argv[offset] = '\0'; -- 2.41.0