Fix handling of files with question mark in the name.
This commit is contained in:
parent
5fc747a64e
commit
e09f869072
12
darkhttpd.c
12
darkhttpd.c
|
@ -489,7 +489,7 @@ static char *split_string(const char *src,
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resolve /./ and /../ in a URL, in-place. Also strip out query params.
|
/* Resolve /./ and /../ in a URL, in-place.
|
||||||
* Returns NULL if the URL is invalid/unsafe, or the original buffer if
|
* Returns NULL if the URL is invalid/unsafe, or the original buffer if
|
||||||
* successful.
|
* successful.
|
||||||
*/
|
*/
|
||||||
|
@ -502,7 +502,7 @@ static char *make_safe_url(char *const url) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Fast case: skip until first double-slash or dot-dir. */
|
/* Fast case: skip until first double-slash or dot-dir. */
|
||||||
for ( ; *src && *src != '?'; ++src) {
|
for ( ; *src; ++src) {
|
||||||
if (*src == '/') {
|
if (*src == '/') {
|
||||||
if (src[1] == '/')
|
if (src[1] == '/')
|
||||||
break;
|
break;
|
||||||
|
@ -517,7 +517,7 @@ static char *make_safe_url(char *const url) {
|
||||||
|
|
||||||
/* Copy to dst, while collapsing multi-slashes and handling dot-dirs. */
|
/* Copy to dst, while collapsing multi-slashes and handling dot-dirs. */
|
||||||
dst = src;
|
dst = src;
|
||||||
while (*src && *src != '?') {
|
while (*src) {
|
||||||
if (*src != '/')
|
if (*src != '/')
|
||||||
*dst++ = *src++;
|
*dst++ = *src++;
|
||||||
else if (*++src == '/')
|
else if (*++src == '/')
|
||||||
|
@ -1853,12 +1853,16 @@ static void generate_dir_listing(struct connection *conn, const char *path) {
|
||||||
|
|
||||||
/* Process a GET/HEAD request. */
|
/* Process a GET/HEAD request. */
|
||||||
static void process_get(struct connection *conn) {
|
static void process_get(struct connection *conn) {
|
||||||
char *decoded_url, *target, *if_mod_since;
|
char *decoded_url, *end, *target, *if_mod_since;
|
||||||
char date[DATE_LEN], lastmod[DATE_LEN];
|
char date[DATE_LEN], lastmod[DATE_LEN];
|
||||||
const char *mimetype = NULL;
|
const char *mimetype = NULL;
|
||||||
const char *forward_to = NULL;
|
const char *forward_to = NULL;
|
||||||
struct stat filestat;
|
struct stat filestat;
|
||||||
|
|
||||||
|
/* strip out query params */
|
||||||
|
if (end = strchr(conn->url, '?'))
|
||||||
|
*end = '\0';
|
||||||
|
|
||||||
/* work out path of file being requested */
|
/* work out path of file being requested */
|
||||||
decoded_url = urldecode(conn->url);
|
decoded_url = urldecode(conn->url);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue