linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: binfmt_script and ^M
@ 2001-03-06 13:55 Jesse Pollard
  2001-03-06 14:54 ` Andreas Schwab
  0 siblings, 1 reply; 61+ messages in thread
From: Jesse Pollard @ 2001-03-06 13:55 UTC (permalink / raw)
  To: schwab, Paul Flinders
  Cc: Paul Flinders, Jeff Mcadams, Rik van Riel, John Kodis,
	Richard B. Johnson, linux-kernel, bug-bash

Andreas Schwab <schwab@suse.de>:Andreas Schwab <schwab@suse.de>Andreas Schwab <schwab@suse.de>
> Paul Flinders <paul@dawa.demon.co.uk> writes:
> 
> |> Andreas Schwab wrote:
> |> 
> |> > This [isspace('\r') == 1] has no significance here.  The right thing to
> |> 
> |> > look at is $IFS, which does not contain \r by default.  The shell only splits
> |> 
> |> > words by "IFS whitespace", and the kernel should be consistent with it:
> |> >
> |> > $ echo -e 'ls foo\r' | sh
> |> > ls: foo: No such file or directory
> |> 
> |> The problem with that argument is that #!<interpreter> can be applied
> |> to more than just shells which understand $IFS, so which environment
> |> variable does the kernel pick?
> 
> The kernel should use the same default value of IFS as the Bourne shell,
> ie. the same value you'll get with /bin/sh -c 'echo "$IFS"'.  This is
> independent of any settings in the environment.
> 
> |> It's a difficult one - logically white space should terminate the interpreter
> 
> No, IFS-whitespace delimits arguments in the Bourne shell.

IFS can be defined in the environment.

The kernel cannot use that definition because it introduces buffer limits
and a potential overflow. Besides, the kernel can run scripts from
applications that may not have or pass IFS, or it's equivalent in whatever
shell is being used (I seem to remember an Icon shell that used commas).

-------------------------------------------------------------------------
Jesse I Pollard, II
Email: pollard@navo.hpc.mil

Any opinions expressed are solely my own.

^ permalink raw reply	[flat|nested] 61+ messages in thread
* Re: binfmt_script and ^M
@ 2001-03-06 15:56 Jesse Pollard
  0 siblings, 0 replies; 61+ messages in thread
From: Jesse Pollard @ 2001-03-06 15:56 UTC (permalink / raw)
  To: schwab, Jesse Pollard
  Cc: Paul Flinders, Paul Flinders, Jeff Mcadams, Rik van Riel,
	John Kodis, Richard B. Johnson, linux-kernel, bug-bash

---------  Received message begins Here  ---------

> 
> Jesse Pollard <pollard@tomcat.admin.navo.hpc.mil> writes:
> 
> |> Andreas Schwab <schwab@suse.de>:Andreas Schwab <schwab@suse.de>Andreas Schwab <schwab@suse.de>
> |> > Paul Flinders <paul@dawa.demon.co.uk> writes:
> |> > 
> |> > |> Andreas Schwab wrote:
> |> > |> 
[snip]
> |> > |> It's a difficult one - logically white space should terminate the interpreter
> |> > 
> |> > No, IFS-whitespace delimits arguments in the Bourne shell.
> |> 
> |> IFS can be defined in the environment.
> 
> No, the shell won't import it.

I wasn't directly referring to the bourn shell or bash. The "shell" is whatever
program is specified on the "#!<shellprog>". The arbitrary <shellprog> could
import it, depending on the definition. (IFS=....; export IFS). If <shellprog>
imports it then it could be used, but only after the <shellprog> is running.

By default, IFS is a non-exported environment variable. It can be exported
to other programs if desired, those other programs can be used in
"#!<shellprog>" constructs.

And some systems do import IFS. IRIX bourn shell will import it:

tomcat 54% sh
$ echo "..${IFS}.."
.. 
..
tomcat 54% sh
$ echo "..${IFS}.."	--(default: space, tab and \n")
.. 
..
$ IFS="         ^M" 	--(space, tab and \r)
$ export IFS
$ echo "..${IFS}.."
.. 
$ sh			-- new subshell
$ echo "..${IFS}.."
.. 			-- space, tab and \r.
$ 

The same test on bash shows that it will not import it:

bash-2.04$ bash
bash-2.04$ echo "..${IFS}.."
.. 
..
bash-2.04$ IFS=" ^M"
bash-2.04$ export IFS
bash-2.04$ echo "..${IFS}.."
.. 
bash-2.04$ bash
bash-2.04$ echo "..${IFS}.."
.. 
..
bash-2.04$

The same test done on ash shows that it will import it:

bash-2.04$ ash
$ echo "..${IFS}.."
.. 
..
$ IFS="         ^M"
$ export IFS
$ echo "..${IFS}.."
.. 
$ ash
$ echo "..${IFS}.."
.. 
$ 

The csh shell, on the other hand, doesn't use IFS. It always uses blank or tab
unless they are escaped with \ or are enclosed in quotes.

Personally, I wouldn't want to change the kernel. There is no good way to
determine which error should be given: the script doesn't exist, or the
shell doesn't exist. Either may be nonexistant, and there is only two
possibilities. First do a "ls -l" on the script (must be readable as well
as executable, second do a "ls -l 'line' where line is the first line
of the shell script, minus the "#!". Sometimes it takes a vi/emacs/...
session to look for any funny characters.

The first case is that the shell script doesn't exist. This is reported
by the users command interpreter. The second case is reported by the
kernel. If all that is wanted is to change the format of the message, then
that should be doable - it has to report a different error than "No such
file..." which is the standard error status for this error. Just because the
file that isn't found is the shell program is no reason to change the status -
it really IS "No such file...". There will be some programs that depend
on this status return (menu/window managers come to mind) to issue an
appropriate status.

If the error is "Permission denied", then the equivalent situation exists.
The difference is that the "ls" alone is enough to determine why. (permission
may be denied for the shell program as well as the script).

A case can be made that the shell programs (bash/ash/csh...) do not do a
complete analysis of the exit status. All they appear to do is a "perror".

If the command does exist, then assume it is the shell program that is
missing?? I would implement this by doing a "stat" on the command path (if
it doesn't exist/permission denied/whatever - issue message about the command
path), then do the exec, followed by the return status analysis. Of course
this isn't easy when using execl, which is why it isn't done - perhaps a
change to the exec.. library funtions?

This is a user mode issue and not a kernel issue.

-------------------------------------------------------------------------
Jesse I Pollard, II
Email: pollard@navo.hpc.mil

Any opinions expressed are solely my own.

^ permalink raw reply	[flat|nested] 61+ messages in thread
* Re: binfmt_script and ^M
@ 2001-03-05 21:15 Andries.Brouwer
  0 siblings, 0 replies; 61+ messages in thread
From: Andries.Brouwer @ 2001-03-05 21:15 UTC (permalink / raw)
  To: P.Flinders, pozsy; +Cc: bug-bash, jeffm, kodis, linux-kernel, riel, root

> And what does POSIX say about "#!/bin/sh\r" ?

Nothing at all. The #! construction is not part of any standard
right now. The implementation is messy - different operating systems
do vaguely similar things, but all details differ.
Linux can do whatever it wants.
Of course it helps portability if we stay close to what other OSs do.

There is some discussion at
  http://www.cwi.nl/~aeb/std/hashexclam-1.html
Additions and corrections welcome.

In this particular case I have no strong opinion,
but would not object to removing the '\r'.

The standard defines whitespace in the POSIX locale, as one or more
<blank>s (<space>s and <tab>s), <newline>s, <carriage-return>s,
<form-feed>s, and <vertical-tab>s.
Some systems strip the #! line for trailing whitespace, some don't.

Andries

^ permalink raw reply	[flat|nested] 61+ messages in thread
* Re: binfmt_script and ^M
@ 2001-03-05 19:14 Jesse Pollard
  2001-03-06 20:54 ` Thorsten Glaser Geuer
  0 siblings, 1 reply; 61+ messages in thread
From: Jesse Pollard @ 2001-03-05 19:14 UTC (permalink / raw)
  To: kodis, Richard B. Johnson; +Cc: linux-kernel, bug-bash

John Kodis <kodis@mail630.gsfc.nasa.gov>:
> On Mon, Mar 05, 2001 at 08:40:22AM -0500, Richard B. Johnson wrote:
> 
> > Somebody must have missed the boat entirely. Unix does not, never
> > has, and never will end a text line with '\r'.
> 
> Unix does not, never has, and never will end a text line with ' ' (a
> space character) or with \t (a tab character).  Yet if I begin a shell
> script with '#!/bin/sh ' or '#!/bin/sh\t', the training white space is
> striped and /bin/sh gets exec'd.  Since \r has no special significance
> to Unix, I'd expect it to be treated the same as any other whitespace
> character -- it should be striped, and /bin/sh should get exec'd.

Actually it does have some significance - it causes a return, then the
following text overwrites the current text. Granted, this is only used
occasionally for generating bold/underline/... 

This is used in some formatters (troff) occasionally, though it tends to
use backspace now.

\r is not considered whitespace, though it should be possible to define
it that way. A line terminator is always \n.

Another point, is that the "#!/bin/sh" can have options added: it can be
"#!/bin/sh -vx" and the option -vx is passed to the shell. The space is
not just "stripped". It is used as a parameter separator. As such, the
"stripping" is only because the first parameter is separated from the
command by whitespace.

-------------------------------------------------------------------------
Jesse I Pollard, II
Email: pollard@navo.hpc.mil

Any opinions expressed are solely my own.

^ permalink raw reply	[flat|nested] 61+ messages in thread
* RE: binfmt_script and ^M
@ 2001-02-27 13:53 Heusden, Folkert van
  2001-02-27 14:26 ` Alistair Riddell
  0 siblings, 1 reply; 61+ messages in thread
From: Heusden, Folkert van @ 2001-02-27 13:53 UTC (permalink / raw)
  To: Ivo Timmermans; +Cc: linux-kernel

> > When running a script (perl in this case) that has DOS-style newlines
> > (\r\n), Linux 2.4.2 can't find an interpreter because it doesn't
> > recognize the \r.  The following patch should fix this (untested).
> _should_ it work with the \r in it?
IV> IMHO, yes.  This set of files were created on Windows, then zipped and
IV> uploaded to a Linux server, unpacked.  This does not change the \r.

But; it's not that much of hassle to run it trough some awk/sed/whatsoever
script, would it? Imho there should be as less as possible code in the
kernel which could've also been done in user-space.

> +	if (cp - 1 == '\r')				<------- *)
> There might be a problem with your patch: at the '*)': if the '\n' is the
> first character on the line, the cp-1 (which should be *(cp-1) I think)
IV> You're right there.

Phew, then I have at least 1 thing right in my message since I was wrong
with:

> would point before the buffer which can be un-allocated memory.

If only I had read the code myself :o)

IV> No, the first two characters are always `#!'.

Yes, absolutely right.

^ permalink raw reply	[flat|nested] 61+ messages in thread
* RE: binfmt_script and ^M
@ 2001-02-27 13:42 Heusden, Folkert van
  2001-02-27 13:38 ` Ivo Timmermans
  2001-02-27 14:01 ` Bruce Harada
  0 siblings, 2 replies; 61+ messages in thread
From: Heusden, Folkert van @ 2001-02-27 13:42 UTC (permalink / raw)
  To: Ivo Timmermans, linux-kernel

> When running a script (perl in this case) that has DOS-style newlines
> (\r\n), Linux 2.4.2 can't find an interpreter because it doesn't
> recognize the \r.  The following patch should fix this (untested).

_should_ it work with the \r in it?

There might be a problem with your patch: at the '*)': if the '\n' is the
first character on the line, the cp-1 (which should be *(cp-1) I think)
would point before the buffer which can be un-allocated memory.



--- binfmt_script.c~	Mon Feb 26 17:42:09 2001
+++ binfmt_script.c	Tue Feb 27 13:39:47 2001
@@ -36,6 +36,8 @@
 	bprm->buf[BINPRM_BUF_SIZE - 1] = '\0';
 	if ((cp = strchr(bprm->buf, '\n')) == NULL)
 		cp = bprm->buf+BINPRM_BUF_SIZE-1;
+	if (cp - 1 == '\r')				<------- *)
+	  cp--;
 	*cp = '\0';
 	while (cp > bprm->buf) {
 		cp--;


Greetings,
Folkert van Heusden
[ www.vanheusden.com ]

^ permalink raw reply	[flat|nested] 61+ messages in thread
* binfmt_script and ^M
@ 2001-02-27 13:03 Ivo Timmermans
  2001-02-27 13:44 ` Alan Cox
  0 siblings, 1 reply; 61+ messages in thread
From: Ivo Timmermans @ 2001-02-27 13:03 UTC (permalink / raw)
  To: linux-kernel

When running a script (perl in this case) that has DOS-style newlines
(\r\n), Linux 2.4.2 can't find an interpreter because it doesn't
recognize the \r.  The following patch should fix this (untested).

Please Cc me on replies, I'm not on this list.  Thanks.


--- binfmt_script.c~	Mon Feb 26 17:42:09 2001
+++ binfmt_script.c	Tue Feb 27 13:39:47 2001
@@ -36,6 +36,8 @@
 	bprm->buf[BINPRM_BUF_SIZE - 1] = '\0';
 	if ((cp = strchr(bprm->buf, '\n')) == NULL)
 		cp = bprm->buf+BINPRM_BUF_SIZE-1;
+	if (cp - 1 == '\r')
+	  cp--;
 	*cp = '\0';
 	while (cp > bprm->buf) {
 		cp--;

-- 
Ivo Timmermans

^ permalink raw reply	[flat|nested] 61+ messages in thread

end of thread, other threads:[~2001-03-09 16:58 UTC | newest]

Thread overview: 61+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-06 13:55 binfmt_script and ^M Jesse Pollard
2001-03-06 14:54 ` Andreas Schwab
  -- strict thread matches above, loose matches on Subject: below --
2001-03-06 15:56 Jesse Pollard
2001-03-05 21:15 Andries.Brouwer
2001-03-05 19:14 Jesse Pollard
2001-03-06 20:54 ` Thorsten Glaser Geuer
2001-02-27 13:53 Heusden, Folkert van
2001-02-27 14:26 ` Alistair Riddell
2001-02-27 23:22   ` David
2001-02-28 14:07     ` Jamie Lokier
2001-02-28 22:23       ` H. Peter Anvin
2001-02-27 13:42 Heusden, Folkert van
2001-02-27 13:38 ` Ivo Timmermans
2001-02-27 19:20   ` Jamie Lokier
2001-02-27 19:59     ` Don Dugger
2001-02-27 21:35   ` Rogier Wolff
2001-02-27 14:01 ` Bruce Harada
2001-02-27 13:03 Ivo Timmermans
2001-02-27 13:44 ` Alan Cox
2001-02-27 13:47   ` Ivo Timmermans
2001-02-27 13:54     ` Alan Cox
2001-02-27 14:36       ` Rogier Wolff
2001-02-28 20:10   ` Erik Hensema
2001-03-01 12:04     ` Pavel Machek
2001-03-05 13:20       ` Jan Nieuwenhuizen
2001-03-05 13:37         ` Andreas Schwab
2001-03-05 13:40         ` Richard B. Johnson
2001-03-05 14:55           ` John Kodis
2001-03-05 15:25             ` Rik van Riel
2001-03-05 15:59               ` Jeff Mcadams
2001-03-05 16:18                 ` Paul Flinders
2001-03-05 17:12                   ` Andreas Schwab
2001-03-05 19:54                     ` Paul Flinders
2001-03-05 20:09                       ` Paul Flinders
2001-03-06 10:41                       ` Andreas Schwab
2001-03-06 12:33                         ` Paul Flinders
2001-03-06 14:45                           ` Laramie Leavitt
2001-03-06 15:12                             ` Sean Hunter
2001-03-06 15:37                               ` David Weinehall
2001-03-06 21:10                                 ` Thorsten Glaser Geuer
     [not found]                                   ` <20010308130145.O20737@dev.sportingbet.com>
2001-03-09 16:52                                     ` Thorsten Glaser Geuer
2001-03-06 15:53                               ` James A. Sutherland
2001-03-07  8:29                               ` Ondrej Sury
2001-03-06 16:59                             ` Xavier Bestel
2001-03-05 18:58                   ` Pozsar Balazs
2001-03-05 20:39                     ` Robert Read
2001-03-05 21:05                       ` Pozsar Balazs
2001-03-05 22:34                         ` Robert Read
2001-03-06 15:14                           ` Jeff Coy
2001-03-06 18:15                             ` Peter Samuelson
2001-03-06 18:36                               ` Jeff Coy
2001-03-06 20:26                                 ` John Kodis
2001-03-06 20:43                                   ` Andreas Schwab
2001-03-06  2:18                       ` Richard B. Johnson
2001-03-05 15:50             ` Richard B. Johnson
2001-03-05 16:53               ` H. Peter Anvin
2001-03-05 21:48             ` Dr. Kelsey Hudson
2001-03-06 18:19               ` Peter Samuelson
2001-03-06 21:04                 ` Dr. Kelsey Hudson
2001-03-05 16:37           ` Erik Hensema
2001-03-05 22:13             ` Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).