Re: [Patch] Support UTF-8 scripts

From: "Martin v. Löwis"
Date: Sat Sep 17 2005 - 01:45:39 EST


Bodo Eggert wrote:
> BTW2: However, I don't like the patch.
>
> I'd first check for a utf-8 signature, and if it's found, adjust the
> buffer offset by 3. Then I'd run the old code checking for the sh_bang.
> OTOH, I just read the patch and not the .c file, maybe (unlikely) my idea
> wouldn't work correctly.

I believe this wouldn't work. binfmt_script currently has the code

for (cp = bprm->buf+2; (*cp == ' ') || (*cp == '\t'); cp++);

to get out the (start of the) interpreter file name. This knows
implicitly that you need to skip two bytes #!; for UTF-8 signatures,
it would be 5 bytes.

Now, if you meant to suggest that bprm->buf should be adjusted (e.g.
through 'brpm->buf += 3'): this cannot work, either. It would break
subsequent binfmt modules which assume that bprm->buf is the first
1KiB (or so) of the file to be executed.

If you suggest that the patch should merely check for the signature,
and then skip it: this is what the patch does.

Regards,
Martin

P.S. I just noticed there is a

bprm->buf[BINPRM_BUF_SIZE - 1] = '\0';

which seems incorrect: it puts a null-byte into the buffer data,
thus (slightly) corrupting the data for subsequent binfmt modules
(although it already knows the file starts with #!, so the
subsequent modules will fail, anyway)

Also, I think the above loop should also terminate for '

*cp == '\0'

if there is neither a space nor a tab in the file.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/