Bug in #! processing

Scot Hetzel swhetzel at gmail.com
Thu Sep 30 07:45:48 PDT 2004

On Thu, 30 Sep 2004 13:21:54 +0100, Ceri Davies <ceri at submonkey.net> wrote:
> I agree(ish); I don't think that the kernel should do anything special
> here either and I think that the "correct" thing to do would be to back
> out that revision.  Unfortunately the FreeBSD userbase can write a lot
> of scripts in 4 and a half years and we probably can't get away with it.
> Perhaps it could be done in -CURRENT, but I'd really like to see some
> other opinions.  For clarity, what I'm proposing is the application of
> the attached diff.  Opinions from anyone?
Instead of backing out that revision, change the test for # to include
a check for white space before it, this way those who have used the #
character as a comment on the first line won't have to change any

-	for (ihp = &image_header[2]; *ihp != '\n' && *ihp != '#'; ++ihp) {
+	for (ihp = &image_header[2]; *ihp != '\n' && ! (*ihp-1 == '[white
space]' && *ihp == '#'); ++ihp) {

where [white space] could be either a tab or a space character.

or just check if a dash is before #.

+	for (ihp = &image_header[2]; *ihp != '\n' && ! (*ihp-1 == '-' &&
*ihp == '#'); ++ihp) {


Discaimer: the code may not work as written adjust to your liking.

More information about the freebsd-current mailing list