From owner-freebsd-current@FreeBSD.ORG Sat Oct 2 04:06:46 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AE64D16A4CE for ; Sat, 2 Oct 2004 04:06:46 +0000 (GMT) Received: from northstar.hetzel.org (tc91.hnet.net [38.119.191.91]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4209143D31 for ; Sat, 2 Oct 2004 04:06:45 +0000 (GMT) (envelope-from swhetzel@gmail.com) Received: from northstar.hetzel.org (localhost [127.0.0.1]) by northstar.hetzel.org (8.13.1/8.13.1) with ESMTP id i9248gH2021850 for ; Fri, 1 Oct 2004 23:08:43 -0500 (CDT) (envelope-from swhetzel@gmail.com) Received: (from root@localhost) by northstar.hetzel.org (8.13.1/8.13.1/Submit) id i9248fRu021849; Fri, 1 Oct 2004 23:08:41 -0500 (CDT) (envelope-from swhetzel@gmail.com) Date: Fri, 1 Oct 2004 23:08:41 -0500 (CDT) Message-Id: <200410020408.i9248fRu021849@northstar.hetzel.org> From: "Scot W. Hetzel" To: FreeBSD-Current Subject: Re: Bug in #! processing X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Oct 2004 04:06:46 -0000 The following patch changes the check for end of line, so that a comment on the first line must be preceded by white space (' ' or '\t'). [main.c] #include int main(int ac, char **av) { int i; printf("Main.c test\n"); for(i = 0; i < ac; i++) { printf("%s\n", av[i]); } } [tst.sh] #! ./main -arg1 -#! # comment echo ok Running tst.sh now produces: # ./tst.sh Main.c test ./main -arg1 -#! ./tst.sh Index: imgact_shell.c =================================================================== RCS file: /home/ncvs/src/sys/kern/imgact_shell.c,v retrieving revision 1.26 diff -u -r1.26 imgact_shell.c --- imgact_shell.c 11 Jun 2003 00:56:54 -0000 1.26 +++ imgact_shell.c 1 Oct 2004 12:15:48 -0000 @@ -49,8 +49,11 @@ struct image_params *imgp; { const char *image_header = imgp->image_header; - const char *ihp, *line_endp; + const char *ihp, *prev, *line_endp; char *interp; + boolean_t comment = FALSE; + + prev = NULL; /* a shell script? */ if (((const short *) image_header)[0] != SHELLMAGIC) @@ -73,7 +76,16 @@ /* * Find end of line; return if the line > MAXSHELLCMDLEN long. */ - for (ihp = &image_header[2]; *ihp != '\n' && *ihp != '#'; ++ihp) { + for (ihp = &image_header[2]; *ihp != '\n' && !comment; ++ihp) { + if ( prev != NULL && + (( *prev == ' ' || *prev == '\t' ) && *ihp == '#' )) { + ihp = prev; + comment = TRUE; + /* Skip over trailing spaces */ + while ((*ihp == ' ') || (*ihp == '\t')) ihp--; + } else + prev = ihp; + if (ihp >= &image_header[MAXSHELLCMDLEN]) return(ENAMETOOLONG); }