Strange bug in sh quoting on Ultrix (and other BSD systems?)

Strange bug in sh quoting on Ultrix (and other BSD systems?)

Post by Atiqullah Hash » Mon, 16 Mar 1992 15:24:50




Quote:>I have encountered a peculiar bug in /bin/sh on Ultrix 4.0 and Ultrix
>3.1.  To recreate it, do the following:

>    echo "echo foo ran" | foo
>    chmod +x foo
>    sh -c "\/\f\o\o"

Replace your first line with:
    echo "echo foo ran" > foo
or
    echo "echo foo ran" >> foo

--
Atiqullah Hashmi                    
UTA (Univ. of Texas at Arlington)  

 
 
 

Strange bug in sh quoting on Ultrix (and other BSD systems?)

Post by Ian Lance Tayl » Mon, 16 Mar 1992 08:52:59


I have encountered a peculiar bug in /bin/sh on Ultrix 4.0 and Ultrix
3.1.  To recreate it, do the following:

    echo "echo foo ran" | foo
    chmod +x foo
    sh -c "\/\f\o\o"

In the final line, I assume that foo is in the root directory.  This
is probably false.  You should put in the directory you are working
in, quoting each character with a backslash.  For example, if you are
in /usr/ian:

    sh -c "\/\u\s\r\/\i\a\n\/\f\o\o"

On Ultrix 4.0 I get something like
    /bin/sh: 8: cannot open
The actual character which appears instead of '8' varies.

On Ultrix 3.1 I get
    /bin/sh: /usr/ian/foo: not found

In both cases it should print
    foo ran

On both systems this works fine with sh5.  It also works on SCO 3.2.2.

If I don't quote some of the characters, it sometimes works.  I've
been unable to find any consistency to it.

I'm doing this extensive quoting in order to safely run a program with
arguments using /bin/sh without having the arguments expanded by the
shell.  Specifically, this is for a UUCP program.  uuxqt tries to run
the program using execve.  If that fails with ENOEXEC, it quotes each
character in the execution request (as shown) and passes it to
/bin/sh.  If uuxqt does not quote all special characters, various
sorts of chicanery become possible.  Quoting every character is not,
of course, necessary, but it's convenient and in any case I don't know
when I will run into this problem.

What I'd like to know is:

    1) Is this a known bug?

    2) Is it specific to Ultrix, or does it happen on other BSD
       derivatives?

    3) How do I work around it?

This site does not get comp.unix.shell, so if you respond only to that
newsgroup please also mail me a copy.

Many thanks.
--

First person to identify this quote wins a free e-mail message:
``Every so many years he went to England to visit--judging by the
  photographs he showed us--a sundial and some oak trees.''

 
 
 

Strange bug in sh quoting on Ultrix (and other BSD systems?)

Post by Ian Lance Tayl » Tue, 17 Mar 1992 03:59:21




>>I have encountered a peculiar bug in /bin/sh on Ultrix 4.0 and Ultrix
>>3.1.  To recreate it, do the following:

>>    echo "echo foo ran" | foo
>>    chmod +x foo
>>    sh -c "\/\f\o\o"
>Replace your first line with:
>    echo "echo foo ran" > foo
>or
>    echo "echo foo ran" >> foo

Right.  Please replace this stupid typo in my previous article, and
then read it again.  Sorry about that.  Obviously I did it right when
I tested it because, as noted, it works with sh5 and on SCO.
--

First person to identify this quote wins a free e-mail message:
``Every so many years he went to England to visit--judging by the
  photographs he showed us--a sundial and some oak trees.''
 
 
 

1. Strange bug in sh quoting on Ultrix (and other BSD systems?)

I have encountered a peculiar bug in /bin/sh on Ultrix 4.0 and Ultrix
3.1.  To recreate it, do the following:

    echo "echo foo ran" | foo
    chmod +x foo
    sh -c "\/\f\o\o"

In the final line, I assume that foo is in the root directory.  This
is probably false.  You should put in the directory you are working
in, quoting each character with a backslash.  For example, if you are
in /usr/ian:

    sh -c "\/\u\s\r\/\i\a\n\/\f\o\o"

On Ultrix 4.0 I get something like
    /bin/sh: 8: cannot open
The actual character which appears instead of '8' varies.

On Ultrix 3.1 I get
    /bin/sh: /usr/ian/foo: not found

In both cases it should print
    foo ran

On both systems this works fine with sh5.  It also works on SCO 3.2.2.

If I don't quote some of the characters, it sometimes works.  I've
been unable to find any consistency to it.

I'm doing this extensive quoting in order to safely run a program with
arguments using /bin/sh without having the arguments expanded by the
shell.  Specifically, this is for a UUCP program.  uuxqt tries to run
the program using execve.  If that fails with ENOEXEC, it quotes each
character in the execution request (as shown) and passes it to
/bin/sh.  If uuxqt does not quote all special characters, various
sorts of chicanery become possible.  Quoting every character is not,
of course, necessary, but it's convenient and in any case I don't know
when I will run into this problem.

What I'd like to know is:

    1) Is this a known bug?

    2) Is it specific to Ultrix, or does it happen on other BSD
       derivatives?

    3) How do I work around it?

This site does not get comp.unix.shell, so if you respond only to that
newsgroup please also mail me a copy.

Many thanks.
--

First person to identify this quote wins a free e-mail message:
``Every so many years he went to England to visit--judging by the
  photographs he showed us--a sundial and some oak trees.''

2. IDE CDROM recognition problem. (correction)

3. System functions in BSD and others *nix systems.

4. IDE OOPS in latest BK

5. Q: sh: Can I quote '"' in a double quoted string?

6. rdist and rsh

7. Why this code works on AIX, NeXT, BUT NOT OTHERS (SunOS, Ultrix) ?

8. SMTP doesn't work right?

9. Batch Processing System for DEC System 5500 Ultrix Wanted.

10. sh vs. sh5 in ultrix

11. getty wizardy on Ultrix (and/or any BSD?)

12. sh(1) question from a "quoting paranoiac" :-)

13. sh/ksh/bash quoting brain tease