From 3329047579e5047732ddf3f2fab8d1c68572d261 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Sun, 31 Oct 2021 12:37:40 +0000 Subject: [PATCH] More explicit check on hm->uri.len --- mongoose.c | 2 +- src/http.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mongoose.c b/mongoose.c index 66782008..fee4a69a 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1478,7 +1478,7 @@ static int uri_to_path2(struct mg_connection *c, struct mg_http_message *hm, flags = fs->stat(path, NULL, NULL); // Does it exist? if (flags == 0) { mg_http_reply(c, 404, "", "Not found\n"); // Does not exist, doh - } else if ((flags & MG_FS_DIR) && hm->uri.len && + } else if ((flags & MG_FS_DIR) && hm->uri.len > 0 && hm->uri.ptr[hm->uri.len - 1] != '/') { mg_printf(c, "HTTP/1.1 301 Moved\r\n" diff --git a/src/http.c b/src/http.c index a58e214f..cf36a479 100644 --- a/src/http.c +++ b/src/http.c @@ -732,7 +732,7 @@ static int uri_to_path2(struct mg_connection *c, struct mg_http_message *hm, flags = fs->stat(path, NULL, NULL); // Does it exist? if (flags == 0) { mg_http_reply(c, 404, "", "Not found\n"); // Does not exist, doh - } else if ((flags & MG_FS_DIR) && hm->uri.len && + } else if ((flags & MG_FS_DIR) && hm->uri.len > 0 && hm->uri.ptr[hm->uri.len - 1] != '/') { mg_printf(c, "HTTP/1.1 301 Moved\r\n"