summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko2008-02-11 16:26:22 +0000
committerDenis Vlasenko2008-02-11 16:26:22 +0000
commitfc213058921209263b94a1e1a000718f2d61ebee (patch)
tree5e203ba78b7c56729298208dd8def48d9d51ae7d /networking
parentf536b99d2646cee6c86e025d29d4a8ae12989e1b (diff)
downloadbusybox-fc213058921209263b94a1e1a000718f2d61ebee.zip
busybox-fc213058921209263b94a1e1a000718f2d61ebee.tar.gz
httpd: fix bug where we did chdir("") if CGI path had only one "/".
httpd: fix bug 2004: wrong argv when interpreter is invoked +8 bytes growth
Diffstat (limited to 'networking')
-rw-r--r--networking/httpd.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index 3ac9b90..779f070 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -1417,37 +1417,39 @@ static void send_cgi_and_exit(
* If CGI really wants that, it can always do dup itself. */
/* dup2(1, 2); */
- /* script must have absolute path */
script = strrchr(fullpath, '/');
//fullpath is a result of concat_path_file and always has '/'
//if (!script)
// goto error_execing_cgi;
*script = '\0';
/* chdiring to script's dir */
- if (chdir(fullpath) == 0) {
- char *argv[2];
+ if (chdir(script == fullpath ? "/" : fullpath) == 0) {
+ char *argv[3];
+
+ *script++ = '/'; /* repair fullpath */
+ /* set argv[0] to name without path */
+ argv[0] = script;
+ argv[1] = NULL;
+
#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
- char *interpr = NULL;
- char *suffix = strrchr(purl, '.');
-
- if (suffix) {
- Htaccess *cur;
- for (cur = script_i; cur; cur = cur->next) {
- if (strcmp(cur->before_colon + 1, suffix) == 0) {
- interpr = cur->after_colon;
- break;
+ {
+ char *suffix = strrchr(script, '.');
+
+ if (suffix) {
+ Htaccess *cur;
+ for (cur = script_i; cur; cur = cur->next) {
+ if (strcmp(cur->before_colon + 1, suffix) == 0) {
+ /* found interpreter name */
+ fullpath = cur->after_colon;
+ argv[0] = cur->after_colon;
+ argv[1] = script;
+ argv[2] = NULL;
+ break;
+ }
}
}
}
#endif
- *script = '/';
- /* set argv[0] to name without path */
- argv[0] = script + 1;
- argv[1] = NULL;
-#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
- if (interpr)
- fullpath = interpr;
-#endif
execv(fullpath, argv);
if (verbose)
bb_perror_msg("exec %s", fullpath);