added support for indexed cgi vars

This commit is contained in:
roberto@oneiric64
2012-01-06 19:36:42 +01:00
parent b153033514
commit 4650d2edbb
3 changed files with 56 additions and 3 deletions
+39 -3
View File
@@ -450,7 +450,8 @@ int uwsgi_cgi_request(struct wsgi_request *wsgi_req) {
int i;
pid_t cgi_pid;
int waitpid_status;
char *argv[3];
char **argv;
int nargs = 0;
char full_path[PATH_MAX];
char tmp_path[PATH_MAX];
int cgi_pipe[2];
@@ -813,6 +814,41 @@ clear:
drop_env = drop_env->next;
}
argv = uwsgi_malloc(sizeof(char *) * 3);
// check if we need to parse indexed QUERY_STRING
if (wsgi_req->query_string_len > 0) {
if (!memchr(wsgi_req->query_string, '=', wsgi_req->query_string_len)) {
nargs = 1;
for(i=0;i<wsgi_req->query_string_len;i++) {
if (wsgi_req->query_string[i] == '+')
nargs++;
}
// reallocate argv and qs
argv = uwsgi_malloc(sizeof(char *) * (3+nargs));
char *qs = uwsgi_concat2n(wsgi_req->query_string, wsgi_req->query_string_len, "", 0);
// set the start position of args in argv
i = 1;
if (helper) i = 2;
char *p = strtok(qs, "+");
while(p) {
// create a copy for the url_decoded string
char *arg_copy = uwsgi_str(p);
uint16_t arg_copy_len = strlen(p);
http_url_decode(p, &arg_copy_len, arg_copy);
// and a final copy for shell escaped arg
argv[i] = uwsgi_malloc( (arg_copy_len * 2) +1);
escape_shell_arg(arg_copy, arg_copy_len, argv[i]);
i++;
p = strtok(NULL, "+");
}
}
else {
}
}
if (helper) {
if (!uwsgi_starts_with(helper, strlen(helper), "sym://", 6)) {
void (*cgi_func)(char *) = dlsym(RTLD_DEFAULT, helper+6);
@@ -826,11 +862,11 @@ clear:
}
argv[0] = helper;
argv[1] = command;
argv[2] = NULL;
argv[nargs+2] = NULL;
}
else {
argv[0] = command;
argv[1] = NULL;
argv[nargs+1] = NULL;
}
if (execvp(argv[0], argv)) {
+15
View File
@@ -3519,6 +3519,21 @@ pid_t uwsgi_fork(char *name) {
return pid;
}
void escape_shell_arg(char *src, size_t len, char *dst) {
size_t i;
char *ptr = dst;
for(i=0;i<len;i++) {
if (strchr("&;`'\"|*?~<>^()[]{}$\\\n", src[i])) {
*ptr++= '\\';
}
*ptr++= src[i];
}
*ptr++= 0;
}
void http_url_decode(char *buf, uint16_t *len, char *dst) {
uint16_t i;
+2
View File
@@ -2576,6 +2576,8 @@ struct uwsgi_logger *uwsgi_get_logger(char *);
char *uwsgi_getsockname(int);
char *uwsgi_get_var(struct wsgi_request *, char *, uint16_t, uint16_t *);
void escape_shell_arg(char *, size_t, char *);
#ifdef UWSGI_AS_SHARED_LIBRARY
int uwsgi_init(int, char **, char **);
#endif