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
Misleading error message on popen() when /bin/sh is missing #8240
Comments
Hello I confirm. The glibc This can be seen here: https://sourceware.org/git/?p=glibc.git;a=blob;f=libio/iopopen.c;h=06778cf110ef9b2745664df00bfd37f291e23ff3;hb=HEAD#l210 This can be reproduced with this C code: // test.c
#include <stdio.h>
#include <errno.h>
#include <string.h>
int main() {
errno = 0;
FILE * f = popen("/bin/true", "r");
fprintf(stderr, "f: %px, errno: %d, strerror: %s\n", f, errno, strerror(errno));
}
The gnu man page mentions something about memory allocations and errno:
So it may be done on purpose. However, this doesn't appears to be standard behavior. Compiling against musl libc has different results:
We could trigger a different error when errno is ENOMEM, but other libcs appear to set errno to ENOMEM to indicate memory allocation failures. |
Reported a glibc issue: https://sourceware.org/bugzilla/show_bug.cgi?id=29016 |
My opinion is that when php calls The documentation at https://www.php.net/manual/en/function.popen.php does not emphasize enough that the Given the spare documentation, |
Yes, this could be a way to fix this. I want to hear from the glibc people before taking a decision. Agreed that the documentation doesn't emphasize enough that I think that currently all |
The issue has been fixed in glibc: https://sourceware.org/bugzilla/show_bug.cgi?id=29016 |
Description
I use PHP 7.4.28, but I do not expect that the described problem has changed in newer versions.
I run PHP-FPM in chrooted environment. That environment had no
/bin/sh
. The php-fpm.conf file contans:so I would expect that the file is executed, whenever PHP's mail() function is called. As it turned out, at least when calling WordPress’
wp_mail()
, and running php-fpm understrace
, php calls/bin/sh /chr/sbin/mini_sendmail
. The same happens, when I call justpopen('/ldconfig', 'r')
. The error message in the latter case is “Cannot allocate memory”, in the former case the error message was that the process cannot be forked (I do not remember the precise text).Now, when PHP relies on /bin/sh to call
exec()
orsystem()
and/bin/sh
is missing, PHP shall neither report, that it cannot fork, nor that it cannot allocate enough memory. It shall report, that/bin/sh
is missing in the chroot-ed environment.PHP Version
PHP 7.4.28,
Operating System
Linux from Scratch
The text was updated successfully, but these errors were encountered: