all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#22354: Hash-bang line length
  2016-01-12  9:14 bug#22354: Test failure when running distcheck from out-of-tree build Taylan Ulrich Bayırlı/Kammer
@ 2016-01-13 10:25 ` Ludovic Courtès
  0 siblings, 0 replies; 10+ messages in thread
From: Ludovic Courtès @ 2016-01-13 10:25 UTC (permalink / raw)
  To: bug-bash; +Cc: 22354

Hello,

The ‘READ_SAMPLE_BUF’ macro in execute_cmd.c reads at most 80 bytes from
the hash-bang line.  This is less than the already-small 128-byte limit
in the Linux kernel¹ and can quite easily be hit².

What about changing it to 128 bytes (as well as the ‘sample’ array) to
at least match Linux?

(It might even make sense to make it bigger so that Bash might succeed
when the kernel simply fails.)

Thanks,
Ludo’.

¹ http://lxr.free-electrons.com/source/include/uapi/linux/binfmts.h#L18
² See <http://bugs.gnu.org/22354>.

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

* bug#22354: Hash-bang line length
       [not found] <87lh7t7p4w.fsf@gnu.org>
@ 2016-01-13 13:19 ` Greg Wooledge
       [not found] ` <20160113131902.GU27325@eeg.ccf.org>
  2016-01-13 16:18 ` Chet Ramey
  2 siblings, 0 replies; 10+ messages in thread
From: Greg Wooledge @ 2016-01-13 13:19 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 22354, bug-bash

On Wed, Jan 13, 2016 at 11:25:03AM +0100, Ludovic Courtès wrote:
> Hello,
> 
> The ???READ_SAMPLE_BUF??? macro in execute_cmd.c reads at most 80 bytes from
> the hash-bang line.  This is less than the already-small 128-byte limit
> in the Linux kernel¹ and can quite easily be hit².

That's actually much bigger than one expects for shebang handling on
any traditional Unix system.

http://www.in-ulm.de/~mascheck/various/shebang/ is by far the most
authoritative source on the topic, and it shows limits of 16 to 32
bytes for the first implementations.  Later, it mentions that Linux's
implementation started at 1022, then was changed to 127.

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

* bug#22354: Hash-bang line length
       [not found] ` <20160113131902.GU27325@eeg.ccf.org>
@ 2016-01-13 13:52   ` Ludovic Courtès
       [not found]   ` <87y4bt60zb.fsf@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Ludovic Courtès @ 2016-01-13 13:52 UTC (permalink / raw)
  To: Greg Wooledge; +Cc: 22354, bug-bash

Greg Wooledge <wooledg@eeg.ccf.org> skribis:

> On Wed, Jan 13, 2016 at 11:25:03AM +0100, Ludovic Courtès wrote:
>> Hello,
>> 
>> The ???READ_SAMPLE_BUF??? macro in execute_cmd.c reads at most 80 bytes from
>> the hash-bang line.  This is less than the already-small 128-byte limit
>> in the Linux kernel¹ and can quite easily be hit².
>
> That's actually much bigger than one expects for shebang handling on
> any traditional Unix system.

Sure, but the fact that it’s smaller than that of the kernel Linux is
problematic: when a hash-bang line > 127 chars is encountered, ‘execve’
fails with ENOENT, so Bash’s fallback code is executed, fails as well,
but it prints a misleading error message with an even more truncated
hash-bang line.

Ludo’.

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

* bug#22354: Hash-bang line length
       [not found]   ` <87y4bt60zb.fsf@gnu.org>
@ 2016-01-13 14:04     ` Greg Wooledge
  2016-01-13 16:21     ` Chet Ramey
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Greg Wooledge @ 2016-01-13 14:04 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 22354, bug-bash

On Wed, Jan 13, 2016 at 02:52:08PM +0100, Ludovic Courtès wrote:
> Sure, but the fact that it???s smaller than that of the kernel Linux is
> problematic: when a hash-bang line > 127 chars is encountered, ???execve???
> fails with ENOENT, so Bash???s fallback code is executed, fails as well,
> but it prints a misleading error message with an even more truncated
> hash-bang line.

Let's suppose bash is changed to read a shebang line of unlimited length.
In your scenario, the script with the 150 character shebang fails at the
kernel level with ENOENT, so bash's fallback code runs, and the script
is executed by a new instance of bash.

This just masks the problem.  Now, your script ONLY works when you
run it from a bash shell.  Not from any other shell, not via C's exec(),
not via find -exec, etc.

That said, it's not bash's place to try to guess how the host system's
kernel will handle the shebang.  I certainly wouldn't expect bash to
tell me "Hey, this is Linux, so your shebang won't work because it's
more than 127 bytes."

I'm not sure what error message or behavior you think bash should employ
in this scenario.  I don't see any clear "best" choice here.

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

* bug#22354: Hash-bang line length
       [not found] <87lh7t7p4w.fsf@gnu.org>
  2016-01-13 13:19 ` bug#22354: Hash-bang line length Greg Wooledge
       [not found] ` <20160113131902.GU27325@eeg.ccf.org>
@ 2016-01-13 16:18 ` Chet Ramey
  2 siblings, 0 replies; 10+ messages in thread
From: Chet Ramey @ 2016-01-13 16:18 UTC (permalink / raw)
  To: Ludovic Courtès, bug-bash; +Cc: 22354, chet.ramey

On 1/13/16 5:25 AM, Ludovic Courtès wrote:
> Hello,
> 
> The ‘READ_SAMPLE_BUF’ macro in execute_cmd.c reads at most 80 bytes from
> the hash-bang line.  This is less than the already-small 128-byte limit
> in the Linux kernel¹ and can quite easily be hit².

That limit is huge compared to other Unixes, btw.

> What about changing it to 128 bytes (as well as the ‘sample’ array) to
> at least match Linux?
> 
> (It might even make sense to make it bigger so that Bash might succeed
> when the kernel simply fails.)

If the kernel returns an errno other than ENOEXEC, bash isn't going to
`succeed'.  This is entirely a cosmetic issue concerning the error message
bash prints when execve fails.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

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

* bug#22354: Hash-bang line length
       [not found]   ` <87y4bt60zb.fsf@gnu.org>
  2016-01-13 14:04     ` Greg Wooledge
@ 2016-01-13 16:21     ` Chet Ramey
       [not found]     ` <20160113140441.GZ27325@eeg.ccf.org>
       [not found]     ` <56967976.2080908@case.edu>
  3 siblings, 0 replies; 10+ messages in thread
From: Chet Ramey @ 2016-01-13 16:21 UTC (permalink / raw)
  To: Ludovic Courtès, Greg Wooledge; +Cc: 22354, bug-bash, chet.ramey

On 1/13/16 8:52 AM, Ludovic Courtès wrote:
> Greg Wooledge <wooledg@eeg.ccf.org> skribis:
> 
>> On Wed, Jan 13, 2016 at 11:25:03AM +0100, Ludovic Courtès wrote:
>>> Hello,
>>>
>>> The ???READ_SAMPLE_BUF??? macro in execute_cmd.c reads at most 80 bytes from
>>> the hash-bang line.  This is less than the already-small 128-byte limit
>>> in the Linux kernel¹ and can quite easily be hit².
>>
>> That's actually much bigger than one expects for shebang handling on
>> any traditional Unix system.
> 
> Sure, but the fact that it’s smaller than that of the kernel Linux is
> problematic: when a hash-bang line > 127 chars is encountered, ‘execve’
> fails with ENOENT, so Bash’s fallback code is executed, fails as well,

No.  Since the execve fails with ENOENT, bash just prints an error
message.

> but it prints a misleading error message with an even more truncated
> hash-bang line.

Again, it's only a cosmetic issue.  I don't have a problem with increasing
the buffer size, but let's not pretend it's anything but that.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

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

* bug#22354: Hash-bang line length
       [not found]     ` <20160113140441.GZ27325@eeg.ccf.org>
@ 2016-01-13 16:23       ` Chet Ramey
       [not found]       ` <56967A06.8040104@case.edu>
  1 sibling, 0 replies; 10+ messages in thread
From: Chet Ramey @ 2016-01-13 16:23 UTC (permalink / raw)
  To: Greg Wooledge, Ludovic Courtès; +Cc: 22354, bug-bash, chet.ramey

On 1/13/16 9:04 AM, Greg Wooledge wrote:
> On Wed, Jan 13, 2016 at 02:52:08PM +0100, Ludovic Courtès wrote:
>> Sure, but the fact that it???s smaller than that of the kernel Linux is
>> problematic: when a hash-bang line > 127 chars is encountered, ???execve???
>> fails with ENOENT, so Bash???s fallback code is executed, fails as well,
>> but it prints a misleading error message with an even more truncated
>> hash-bang line.
> 
> Let's suppose bash is changed to read a shebang line of unlimited length.
> In your scenario, the script with the 150 character shebang fails at the
> kernel level with ENOENT, so bash's fallback code runs, and the script
> is executed by a new instance of bash.

No, it isn't.  The execve fails with ENOENT, so bash just prints an error
message containing the interpreter name, which Ludo is reporting is
truncated.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

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

* bug#22354: Hash-bang line length
       [not found]       ` <56967A06.8040104@case.edu>
@ 2016-01-13 16:39         ` Greg Wooledge
  0 siblings, 0 replies; 10+ messages in thread
From: Greg Wooledge @ 2016-01-13 16:39 UTC (permalink / raw)
  To: Chet Ramey; +Cc: 22354, bug-bash

On Wed, Jan 13, 2016 at 11:23:34AM -0500, Chet Ramey wrote:
> On 1/13/16 9:04 AM, Greg Wooledge wrote:
> > On Wed, Jan 13, 2016 at 02:52:08PM +0100, Ludovic Courtès wrote:
> >> Sure, but the fact that it???s smaller than that of the kernel Linux is
> >> problematic: when a hash-bang line > 127 chars is encountered, ???execve???
> >> fails with ENOENT, so Bash???s fallback code is executed, fails as well,
> >> but it prints a misleading error message with an even more truncated
> >> hash-bang line.
> > 
> > Let's suppose bash is changed to read a shebang line of unlimited length.
> > In your scenario, the script with the 150 character shebang fails at the
> > kernel level with ENOENT, so bash's fallback code runs, and the script
> > is executed by a new instance of bash.
> 
> No, it isn't.  The execve fails with ENOENT, so bash just prints an error
> message containing the interpreter name, which Ludo is reporting is
> truncated.

Ah.  You're right, and I should have double-checked Ludo's understanding
of the code before responding.  I assumed Ludo's assertion was correct,
but it's not.

The "fallback code" is only executed when execve() fails with ENOEXEC.

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

* bug#22354: Hash-bang line length
       [not found]     ` <56967976.2080908@case.edu>
@ 2016-01-13 17:41       ` Ludovic Courtès
       [not found]       ` <87vb6x2x7u.fsf@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Ludovic Courtès @ 2016-01-13 17:41 UTC (permalink / raw)
  To: Chet Ramey; +Cc: Greg Wooledge, bug-bash, 22354

Chet Ramey <chet.ramey@case.edu> skribis:

> On 1/13/16 8:52 AM, Ludovic Courtès wrote:
>> Greg Wooledge <wooledg@eeg.ccf.org> skribis:
>> 
>>> On Wed, Jan 13, 2016 at 11:25:03AM +0100, Ludovic Courtès wrote:
>>>> Hello,
>>>>
>>>> The ???READ_SAMPLE_BUF??? macro in execute_cmd.c reads at most 80 bytes from
>>>> the hash-bang line.  This is less than the already-small 128-byte limit
>>>> in the Linux kernel¹ and can quite easily be hit².
>>>
>>> That's actually much bigger than one expects for shebang handling on
>>> any traditional Unix system.
>> 
>> Sure, but the fact that it’s smaller than that of the kernel Linux is
>> problematic: when a hash-bang line > 127 chars is encountered, ‘execve’
>> fails with ENOENT, so Bash’s fallback code is executed, fails as well,
>
> No.  Since the execve fails with ENOENT, bash just prints an error
> message.

Right, sorry for the confusion.

>> but it prints a misleading error message with an even more truncated
>> hash-bang line.
>
> Again, it's only a cosmetic issue.  I don't have a problem with increasing
> the buffer size, but let's not pretend it's anything but that.

Exactly.  I was talking about the “bad interpreter” error message
specifically.

Ludo’.

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

* bug#22354: Hash-bang line length
       [not found]       ` <87vb6x2x7u.fsf@gnu.org>
@ 2016-01-13 20:47         ` Chet Ramey
  0 siblings, 0 replies; 10+ messages in thread
From: Chet Ramey @ 2016-01-13 20:47 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 22354, bug-bash, Greg Wooledge, chet.ramey

On 1/13/16 12:41 PM, Ludovic Courtès wrote:

>>> but it prints a misleading error message with an even more truncated
>>> hash-bang line.
>>
>> Again, it's only a cosmetic issue.  I don't have a problem with increasing
>> the buffer size, but let's not pretend it's anything but that.
> 
> Exactly.  I was talking about the “bad interpreter” error message
> specifically.

OK, we'll try it.  Can't hurt.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

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

end of thread, other threads:[~2016-01-13 20:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <87lh7t7p4w.fsf@gnu.org>
2016-01-13 13:19 ` bug#22354: Hash-bang line length Greg Wooledge
     [not found] ` <20160113131902.GU27325@eeg.ccf.org>
2016-01-13 13:52   ` Ludovic Courtès
     [not found]   ` <87y4bt60zb.fsf@gnu.org>
2016-01-13 14:04     ` Greg Wooledge
2016-01-13 16:21     ` Chet Ramey
     [not found]     ` <20160113140441.GZ27325@eeg.ccf.org>
2016-01-13 16:23       ` Chet Ramey
     [not found]       ` <56967A06.8040104@case.edu>
2016-01-13 16:39         ` Greg Wooledge
     [not found]     ` <56967976.2080908@case.edu>
2016-01-13 17:41       ` Ludovic Courtès
     [not found]       ` <87vb6x2x7u.fsf@gnu.org>
2016-01-13 20:47         ` Chet Ramey
2016-01-13 16:18 ` Chet Ramey
2016-01-12  9:14 bug#22354: Test failure when running distcheck from out-of-tree build Taylan Ulrich Bayırlı/Kammer
2016-01-13 10:25 ` bug#22354: Hash-bang line length Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.