Bug 10906 - /usr/bin/env: endless loop if VAR=ASSIGN present
Summary: /usr/bin/env: endless loop if VAR=ASSIGN present
Status: RESOLVED INVALID
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.28.x
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-29 14:51 UTC by Steffen Nurpmeso
Modified: 2018-03-29 21:18 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steffen Nurpmeso 2018-03-29 14:51:23 UTC
The following loops endlessly unless ABRA=KADABRA is removed (AlpineLinux edge, v1.28.2):

#!/usr/bin/env ABRA=KADABRA sh
echo hoho
Comment 1 Denys Vlasenko 2018-03-29 15:41:31 UTC
This construct does not do what you expect.

Everything after #! goes into argv[1]:

argv[0]='/usr/bin/env'
argv[1]='ABRA=KADABRA sh'
argv[2]='./script'

and argv[2] is script's name. Thus, it won't work with any implementaion of "env".
Comment 2 Steffen Nurpmeso 2018-03-29 21:18:38 UTC
 |This construct does not do what you expect.

Ok, but i think it is still a problem that this loops with 100%
percent CPU usage, endlessly.

 |Everything after #! goes into argv[1]:
 |
 |argv[0]='/usr/bin/env'
 |argv[1]='ABRA=KADABRA sh'
 |argv[2]='./script'
 |
 |and argv[2] is script's name. Thus, it won't work with any implementaion of
 |"env".

Isn't that a pity, what a terrible restriction, it would be so
nice to use.  (At least perl has this -x ... "#!perl" mechanism so
that no wrapper is needed at least there.)

And, not all env(1):

  ?0[steffen@devon shared]$ ./t.sh 
  hoho KADABRA haha
  ?0[steffen@devon shared]$ cat t.sh
  #!/usr/bin/env ABRA=KADABRA sh
  echo hoho $ABRA haha
  ?0[steffen@devon shared]$ strings /usr/bin/env 
  usage: env [-i] [name=value ...] [utility [argument ...]]
  $FreeBSD: src/usr.bin/env/env.c,v 1.11 2002/09/04 23:28:59 dwmalone Exp $

Much better, but not standard, unfortunately.

--steffen