diff --git a/src/httpd.c b/src/httpd.c index c8ca2e1..8111105 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -342,6 +342,12 @@ build_fd_set(fd_set *read, fd_set *write, fd_set *excp) memset(excp, 0, sizeof(fd_set)); } + /* NOTE: httpd->httpc[] is read here without lock. + * This is safe because build_fd_set() runs in the same + * socket_thread as array_add(). array_del() in httpclos + * runs in worker threads but sets entries to NULL before + * removal, and we check for NULL below. + */ for(n=0; n < count; n++) { httpc = httpd->httpc[n]; if (!httpc) continue; /* no client handle? */ @@ -550,7 +556,9 @@ socket_thread(void *arg1, void *arg2) } else { /* add new client to array of clients */ + lock(httpd, 0); array_add(&httpd->httpc, httpc); + unlock(httpd, 0); } } /* if (FD_ISSET(httpd->listen, &read)) */ diff --git a/src/httpdbug.c b/src/httpdbug.c index 3d3c217..96bbac8 100644 --- a/src/httpdbug.c +++ b/src/httpdbug.c @@ -20,25 +20,28 @@ http_debug(HTTPC *httpc, const char *options) http_printf(httpc, "\n"); diff --git a/src/httpfile.c b/src/httpfile.c index da4a1dd..0e59a37 100644 --- a/src/httpfile.c +++ b/src/httpfile.c @@ -283,11 +283,13 @@ ssi_process(HTTPC *httpc, char *ssi) while (isspace(*p)) p++; /* skip any white space */ if (!*p) goto invalid; - p = strtok(p, " "); /* isolate the ssi request */ - if (!p) goto invalid; - - next = strtok(NULL,""); /* remember whatever follows the request */ - if (!next) goto invalid; + /* isolate the ssi request (split at first space) */ + next = p; + while (*next && *next != ' ') next++; + if (!*next) goto invalid; + *next++ = 0; + while (isspace(*next)) next++; + if (!*next) goto invalid; if (http_cmp(p, "echo")==0) { /* next *should* point to whatever follows "