View Issue Details

IDProjectCategoryView StatusLast Update
00020021003.1(2024)/Issue8System Interfacespublic2026-11-16 20:47
Reporterstephane Assigned To 
PrioritynormalSeverityObjectionTypeEnhancement Request
Status Interpretation RequiredResolutionAccepted As Marked 
NameStephane Chazelas
Organization
User Reference
Sectionhttps://pubs.opengroup.org/onlinepubs/9799919799/functions/execl.html
Page Numberhttps://pubs.opengroup.org/onlinepubs/9799919799/functions/execl.html
Line Numberhttps://pubs.opengroup.org/onlinepubs/9799919799/functions/execl.html
Interp StatusPending
Final Accepted Textsee 0002002:0007561
Summary0002002: execlp() / execvp() and commands starting with - or +
DescriptionSimilar to 0001440, related to 0001600

https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/execl.html has:

"""
In the cases where the other members of the exec family of functions would fail and set errno to [ENOEXEC], the execlp() and execvp() functions shall execute a command interpreter and the environment of the executed command shall be as if the process invoked the sh utility using execl() as follows:

execl(<shell path>, <name>, file, <args>, (char *)0);


where <shell path> is an unspecified pathname for the sh utility, <name> is an unspecified string, file is the process image file, and where <args> is zero or more parameters corresponding to any initial non-null arguments passed after arg0 for execlp() or to any initial non-null members of argv starting at argv[1] for execvp().
"""

"file is the process image file" should probably be "file is the pathname to the process image file", but also, if that pathname starts with - or +, such as when invoked as execlp("-dir-/cmd",...) or execlp("+x",...) and +x was found in the current directory because $PATH contains an empty component, then that path will be taken as an option by sh instead of the path to the file being executed.

There's a similar problem in the resolution of 0001600 where

#! /path/to/sh
${0##*/} "$@"


Should be:

#! /path/to/sh --
"${0##*/}" "$@"


(leaving that ${0##*/} unquoted to request split+glob also doesn't make sense here)

Desired ActionFor execlp/execvp, change to:

"""
execl(<shell path>, <name>, "--", file, <args>, (char *)0);


where <shell path> is an unspecified pathname for the sh utility, <name> is an unspecified string, file is the pathname of the process image file, and where <args> is zero or more parameters corresponding to any initial non-null arguments passed after arg0 for execlp() or to any initial non-null members of argv starting at argv[1] for execvp().
"""

Apparently Solaris/Illumos prefix the path with ./ if it starts with - (not +) instead (https://github.com/illumos/illumos-gate/blob/7bbcc14f12e8a235cc9668f76da6d2c9ecf14cd4/usr/src/lib/libc/port/gen/execvp.c#L156-L158). We may want to also allow that even if that means that changes the value of `$0` in the shell script.

For the builtins (0001600 resolution):

#! /path/to/sh --
"${0##*/}" "$@"


Using a single dash as in:

#! /path/to/sh -
"${0##*/}" "$@"


May be more canonical as that's what was done for the Bourne shell.
Tagsissue9

Relationships

related to 0001600 Closed 1003.1(2016/18)/Issue7+TC2 Problems with the suggested single-line shell script: $0 "$@" 

Activities

nick

2026-11-09 17:29

manager   bugnote:0007552

Last edited: 2026-11-09 17:30

Interpretation response
------------------------
The standard clearly states the behavior of execvp and execlp , and conforming implementations must conform to this.

Rationale:
-------------
The behavior specified by the standard contains dangers that users may not realize, and there is no appropriate warning.

Notes to the Editor (not part of this interpretation):
-------------------------------------------------------

Page 867, after line 29504 add a following new sentence:

If the file argument starts with a + or a -, the resulting behavior is undefined.


Page 874, after line 29802, add a new paragraph:

Note for the execlp() and execvp() functions, if the file argument has a leading '+' or '-' character and the file found does not have appropriate execute permission, the shell that is invoked may use this argument as option settings, and run a different script than was intended. Some implementations add a "--" argument to resolve this, but this is not required. Thus, the behavior in this case is undefined.

stephane

2026-11-10 05:46

reporter   bugnote:0007557

Thanks, that's a step in the right direction in my opinion as at least it raises awareness to the potential issue, but some issues remain:

It doesn't address my:

  > "file is the process image file" should probably be "file is the pathname to the process image file"

And that "if the file argument" in the proposed change makes me realise the problem in the original text is that in

  execl(<shell path>, <name>, file, <args>, (char *)0);

That "file" incorrectly refers to the "file" argument passed in:

  execlp(const char *file, const char *arg0, ... /*, (char *)0 */);

It should rather be:

   execl(<shell path>, <name>, <resolved_pathname>, <args>, (char *)0);

Where <resolved_pathname> is the pathname to file resolved as per above (with behaviour undefined if that pathname (not file) starts with - or +). For example:

% PATH=~/bin:/bin ltrace -e execvp env zzz blah
env->execvp("zzz", ["zzz", "blah"] <no return ...>
--- Called exec() ---
+++ exited (status 0) +++
% PATH=~/bin:/bin strace -qqe execve env zzz blah
execve("/bin/env", ["env", "zzz", "blah"], 0x7fffc2ccc440 /* 55 vars */) = 0
execve("/home/chazelas/bin/zzz", ["zzz", "blah"], 0x7ffc48cf3368 /* 55 vars */) = -1 ENOEXEC (Exec format error)
execve("/bin/sh", ["/bin/sh", "/home/chazelas/bin/zzz", "blah"], 0x7ffc48cf3368 /* 55 vars */) = 0


It's the pathname resolved from a $PATH lookup (/home/chazelas/bin/zzz) that was passed as argument to /bin/sh, not zzz (the "file" argument to execvp()).

And:

$ PATH=+dir+:/bin strace -qqe execve env zzz blah
execve("/bin/env", ["env", "zzz", "blah"], 0x7fffe38a6820 /* 55 vars */) = 0
execve("+dir+/zzz", ["zzz", "blah"], 0x7ffda17ab848 /* 55 vars */) = -1 ENOEXEC (Exec format error)
execve("/bin/sh", ["/bin/sh", "+dir+/zzz", "blah"], 0x7ffda17ab848 /* 55 vars */) = 0
/bin/sh: 0: Illegal option -d


(as that execvp() implementation fails to pass the -- option delimiter).

Note that I'm aware of Solaris/Illumos prepending "./" to that pathname when it starts with - (not + in Illumos at least which would be an overlook) as already noted, I don't know if there are any that add the "--" delimiter (or "-" which is more idiomatic for sh as was supported by the Bourne shell).

stephane

2026-11-10 05:49

reporter   bugnote:0007558

The proposed resolution also doesn't address the missing -- / - in

#! /path/to/sh --
"${0##*/}" "$@"

stephane

2026-11-10 06:05

reporter   bugnote:0007559

Also, it is not about "and the file found does not have appropriate execute permission".

If the file does not have appropriate permission, execlp() / execvp() must fail with the appropriate error code (EACESS / EPERM...).

"sh" is only invoked for files that have appropriate execute permission and for which execve() returns ENOEXEC (an executable format not recognised by the system).

nick

2026-11-16 17:23

manager   bugnote:0007561

New interpretation:

Interpretation response
------------------------
The standard clearly states the behavior of execvp and execlp , and conforming implementations must conform to this.

Rationale:
-------------
The behavior specified by the standard contains dangers that users may not realize, and there is no appropriate warning.

Notes to the Editor (not part of this interpretation):
-------------------------------------------------------
Page 867, at line 29502 change

file is the process image file,

to

file is the absolute pathname to the process image file,

    
Page 867, after line 29504 add a following new sentence:
If the file argument starts with a + or a -, the resulting behavior is undefined.

Page 874, after line 29802, add a new paragraph:

Note for the execlp() and execvp() functions, if the file argument has a leading '+' or '-' character and the file found does not have appropriate execute permission is not in a recognized executable format, the shell that is invoked may use this argument as option settings, and run a different script than was intended. Some implementations add a "--" argument to resolve this, but this is not required. Thus, the behavior in this case is undefined.


Page 3865, line 133908-133909, change:
    

#! /path/to/sh
${0##*/} "$@"

to:

#! /path/to/sh -
"${0##*/}" "$@"

(single dash, for consistency with the sh rationale page 3381, line 115197 )

stephane

2026-11-16 20:47

reporter   bugnote:0007564

Re: 0002002:0007561

> file is the absolute pathname to the process image file

It's not. for

  execlp("relative/path", ...)

sh is invoked as

   sh relative/path ...

(though it should be "sh -- relative/path" or "sh ./relative/path" at least when that path starts with - or +).

For

  execlp("cmd", ...)

sh will be called as

  sh some/path/cmd ...

With "some/path" being the first $PATH component where a "cmd" was found, which may or may not be absolute (though it's bad practice to have relative paths in $PATH).

In any case, if it were an absolute pathname, there would not be any issues with + or -.

I would not call that argument "file" as it causes confusion with the "file" argument in the execlp()/execvp() synopsis. That's why I suggested <resolved_pathname> instead.

> If the file argument starts with a + or a -, the resulting behavior is undefined.

The problem is not with the "file" argument to execlp() but with the pathname passed as argument to "sh" here.

> if the file argument has a leading '+' or '-' character and the file found does not have appropriate execute permission

Again, it's not about "having appropriate execute permission". If the file doesn't have appropriate execute permission, it's not a ENOEXEC error that would be returned by "the other members of the exec family of functions", and sh would not be invoked and we would not run into issues with pathnames starting with - or + with those execlp()/execvp() implementations that forget to guard against them.

Issue History

Date Modified Username Field Change
2026-10-28 18:50 stephane New Issue
2026-11-02 16:30 msbrown Relationship added related to 0001600
2026-11-09 17:28 msbrown Tag Attached: issue9
2026-11-09 17:29 nick Note Added: 0007552
2026-11-09 17:30 nick Note Edited: 0007552
2026-11-10 05:46 stephane Note Added: 0007557
2026-11-10 05:49 stephane Note Added: 0007558
2026-11-10 06:05 stephane Note Added: 0007559
2026-11-16 17:23 nick Note Added: 0007561
2026-11-16 17:26 nick Status New => Interpretation Required
2026-11-16 17:26 nick Resolution Open => Accepted As Marked
2026-11-16 17:26 nick Interp Status => Pending
2026-11-16 17:26 nick Final Accepted Text => see 0002002:0007561
2026-11-16 20:47 stephane Note Added: 0007564