From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 318FF39383A8; Mon, 23 Mar 2020 13:48:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 318FF39383A8 From: "pokogiv215 at sweatmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug libc/25715] New: system() returns wrong errors when posix_spawn fails Date: Mon, 23 Mar 2020 13:48:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Version: 2.30 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pokogiv215 at sweatmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Mar 2020 13:48:18 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D25715 Bug ID: 25715 Summary: system() returns wrong errors when posix_spawn fails Product: glibc Version: 2.30 Status: UNCONFIRMED Severity: normal Priority: P2 Component: libc Assignee: unassigned at sourceware dot org Reporter: pokogiv215 at sweatmail dot com CC: drepper.fsp at gmail dot com Target Milestone: --- On linux, I observe a call to system() claiming it's killed by sigbus when really the underlying execv failed with E2BIG. See reproduction in [1]. What I expected to see is system() returning with exit code 127, as per `man system`: * If a shell could not be executed in the child process, then the return value is as though the child shell terminated by calling _exit(2) wi= th the status 127. Less important, but what I also expected is for posix_spawn to return 0 in = this case and to fill in the pid, but instead it returns E2BIG and doesn't fill = in the pid, which is not the behavior described by posix_spawn's man page: The posix_spawn() and posix_spawnp() functions fail only in the case where the underlying fork(2) or vfork(2) call fails; in these cases, these functions return an error number, which will be one of the errors described for fork(2) or vfork(2). The bad return value from system() was introduced in 5fb7fc96350575c9adb1316833e48ca11553be49, which returns posix_spawn's result (an errno) from system (which returns a wait status). The posix_spawn handling of errors in the child seems to have changed unintentionally in 4b4d4056bb154603f36c6f8845757c1012758158 (because ec did= n't use to be set). [1] $ cat a.c #include #include #include #include #include #include #include int main(int argc, char* argv[], char** env) { char cmd[150000]; memset(cmd, 'a', sizeof(cmd)); cmd[sizeof(cmd) - 1] =3D 0; int ret =3D posix_spawn(NULL, "/bin/sh", 0, NULL, (char *[]){"sh", "-c", (char *)cmd, 0}, env); printf("posix_spawn returns: %d =3D %s\n", ret, strerror(ret)); int wstatus =3D system(cmd); if (WIFEXITED(wstatus)) { printf("exited, status=3D%d\n", WEXITSTATUS(wstatus)); } else if (WIFSIGNALED(wstatus)) { printf("killed by signal %d =3D %s\n", WTERMSIG(wstatus), strsignal(WTERMSIG(wstatus))); } else if (WIFSTOPPED(wstatus)) { printf("stopped by signal %d\n", WSTOPSIG(wstatus)); } else if (WIFCONTINUED(wstatus)) { printf("continued\n"); } return 0; } $ gcc a.c && ./a.out posix_spawn returns: 7 =3D Argument list too long killed by signal 7 =3D Bus error --=20 You are receiving this mail because: You are on the CC list for the bug.=