-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"exec PROGRAM LIST" does not work with empty list #16075
Comments
From @paliWhen exec is called with empty list, either via explicit () or implicit, $ perl -e 'exec {"binary"} () or die "exec failed: \"$!\"\n";' $ perl -e 'my @args; exec {"binary"} @args or die "exec failed: \"$!\"\n";' Here is patch which fixes it: Inline Patchdiff --git a/doio.c b/doio.c
index 6f4cd84f8c..32f6e3416f 100644
--- a/doio.c
+++ b/doio.c
@@ -1583,7 +1583,7 @@ Perl_do_aexec5(pTHX_ SV *really, SV **mark, SV **sp,
#if defined(__SYMBIAN32__) || defined(__LIBCATAMOUNT__)
Perl_croak(aTHX_ "exec? I'm not *that* kind of operating system");
#else
- if (sp > mark) {
+ if (sp >= mark) {
const char **a;
const char *tmps = NULL;
Newx(PL_Argv, sp - mark + 1, const char*);
perl -e 'exec {"true"} () or die "exec failed: \"$!\"\n";'; echo $? perl -e 'exec {"false"} () or die "exec failed: \"$!\"\n";'; echo $? |
From @ilmari(via RT) <perlbug-followup@perl.org> writes:
This causes calling execvp() with an empty argv array, which is not However, with this patch "exec {''} ()" and "exec()" segfault a bit exec() crashes on line 1601 while exec {''} () crashes on line 1608: if (really) It gets to that path insted of the "really" branch, because tmps is an I propose explicitly returning ENOENT (which is what execvp() returns if Inline Patchdiff --git a/doio.c b/doio.c
index 6f4cd84f8c..cbaf7e6a33 100644
--- a/doio.c
+++ b/doio.c
@@ -1583,7 +1583,7 @@ Perl_do_aexec5(pTHX_ SV *really, SV **mark, SV **sp,
#if defined(__SYMBIAN32__) || defined(__LIBCATAMOUNT__)
Perl_croak(aTHX_ "exec? I'm not *that* kind of operating system");
#else
- if (sp > mark) {
+ if (sp >= mark) {
const char **a;
const char *tmps = NULL;
Newx(PL_Argv, sp - mark + 1, const char*);
@@ -1598,17 +1598,19 @@ Perl_do_aexec5(pTHX_ SV *really, SV **mark, SV **sp,
*a = NULL;
if (really)
tmps = SvPV_nolen_const(really);
- if ((!really && *PL_Argv[0] != '/') ||
+ if ((!really && PL_Argv[0] && *PL_Argv[0] != '/') ||
(really && *tmps != '/')) /* will execvp use PATH? */
TAINT_ENV(); /* testing IFS here is overkill, probably */
PERL_FPU_PRE_EXEC
if (really && *tmps) {
PerlProc_execvp(tmps,EXEC_ARGV_CAST(PL_Argv));
- } else {
+ } else if (PL_Argv[0]) {
PerlProc_execvp(PL_Argv[0],EXEC_ARGV_CAST(PL_Argv));
- }
+ } else {
+ SETERRNO(ENOENT,LIB_INVARG);
+ }
PERL_FPU_POST_EXEC
- S_exec_failed(aTHX_ (really ? tmps : PL_Argv[0]), fd, do_report);
+ S_exec_failed(aTHX_ (really ? tmps : PL_Argv[0] ? PL_Argv[0] : ""), fd, do_report);
}
do_execfree();
#endif
- ilmari
--
- Twitter seems more influential [than blogs] in the 'gets reported in
the mainstream press' sense at least. - Matt McLeod
- That'd be because the content of a tweet is easier to condense down
to a mainstream media article. - Calle Dybedahl |
The RT System itself - Status changed from 'new' to 'open' |
From @paliOn Monday 10 July 2017 06:58:10 Dagfinn Ilmari Mannsåker via RT wrote:
I cannot currently find POSIX requirement that first arg cannot be NULL.
But, in ISO C89, ISO C99 and also ISO C11, main's argc can be zero. In * The value of argc shall be nonnegative.
Ouh, I have not caught this.
Looks good, thanks for update!
|
From @ilmaripali@cpan.org writes:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html says: | The value in argv[0] should point to a filename string that is It's only a "should", not a "must", so the requirement only applies to
The RATIONALE section of the POSIX exec() man page explains the history: | Early proposals required that the value of argc passed to main() be "one […]
I'm going on holiday for a week today, but unless anyone objects (or
-- |
From @paliOn Thursday 13 July 2017 10:14:41 Dagfinn Ilmari Mannsåker via RT wrote:
Hi! If you are back, can you process this patch? |
From @paliHi! I would like to remind patch in this ticket. |
From @ilmaripali@cpan.org writes:
Sorry for the delay. I've now merged the patch, and it'll be in the - ilmari |
From @jkeenanSince we haven't observed any test failures since Ilmari committed the patch, I'm marking this ticket Resolved. |
@jkeenan - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#131730 (status was 'resolved')
Searchable as RT131730$
The text was updated successfully, but these errors were encountered: