Hi list,
I am using busybox stable 1.34.1.
I'm not sure if I am mixing up something or if this is a missing feature.
If I want to run a .php as an index_page, it won't load - couldn't find the
interpreter. If I explicitly call /index.php it works.
My httpd.conf looks like this:
*.php:/usr/bin/php-cgi
I:index.php
php.ini contains
cgi.force_redirect = 0
I looked into httpd.c and I think I found the problem in 2 sections:
- first:
execv(argv[0], argv); - This argv[0] should contain the interpreter
(php-cgi), while argv[1] should contain the script name (index.php) - this
won't work, because "script" variable is empty, because it was calculated
from static char *url, which only contains the ending "/", and index_page
variable was not added to it. The interpreter should have been looked up by
the script variable's extension (.php), which obviously couldn't have been
done.
- second:
PHP in CGI mode needs a properly filled SCRIPT_FILENAME environment
variable, as noted in a valuable comment in the code. This should contain
the name of the file to execute, and again, because of the *url variable
without the concatenated index_page, it isn't filled correctly. Without
this, calling php-cgi simply fails, even if it has the correct filename for
execv in argv (argv[1]);
I have created a simple patch as a proposal, which works for me. There is
probably a more elegant way, I didn't read all the code, just looked for
the cause of this exact problem.
Regards,
Karoly
make httpd use interpreted cgis as index files
diff -ru --no-dereference src/busybox-1.34.1.orig/busybox-1.34.1/networking/httpd.c src/busybox-1.34.1/networking/httpd.c
--- src/busybox-1.34.1.orig/busybox-1.34.1/networking/httpd.c 2021-06-16 12:02:16.000000000 +0200
+++ src/busybox-1.34.1/networking/httpd.c 2022-10-01 23:31:30.812620570 +0200
@@ -1583,8 +1583,15 @@
/* SCRIPT_FILENAME is required by PHP in CGI mode */
if (home_httpd[0] == '/') {
- char *fullpath = concat_path_file(home_httpd, url);
- setenv1("SCRIPT_FILENAME", fullpath);
+ if (url[strlen(url)-1]=='/') {
+ char *fullpath, *realurl = malloc(sizeof(url)+sizeof(index_page)+1);
+ sprintf(realurl, "%s%s", url, index_page);
+ fullpath = concat_path_file(home_httpd, realurl);
+ setenv1("SCRIPT_FILENAME", fullpath);
+ } else {
+ char *fullpath = concat_path_file(home_httpd, url);
+ setenv1("SCRIPT_FILENAME", fullpath);
+ }
}
/* set SCRIPT_NAME as full path: /cgi-bin/dirs/script.cgi */
setenv1("SCRIPT_NAME", url);
@@ -1665,6 +1672,10 @@
}
script++;
+ if (strcmp(script, "") == 0) {
+ script = index_page;
+ }
+
/* set argv[0] to name without path */
argv[0] = script;
argv[1] = NULL;
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox