From d7c5047fd367227a75eee56013247b3acb311752 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Mon, 23 Feb 2015 00:11:55 +0000 Subject: [PATCH] Fix crash when requesting nonexistent extensionless files (but only if HTMLPATH does not contain a '.') Clean up overuse of strstr. (based on 259ce08f81eaaaa087b6b1994fce7dde81820c52) --- net_io.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net_io.c b/net_io.c index 026df24..e179ec0 100644 --- a/net_io.c +++ b/net_io.c @@ -1202,14 +1202,14 @@ int handleHTTPRequest(struct client *c, char *p) { content_type = MODES_CONTENT_TYPE_HTML; // Default content type ext = strrchr(getFile, '.'); - if (strlen(ext) > 0) { - if (strstr(ext, ".json")) { + if (ext) { + if (!strcmp(ext, ".json")) { content_type = MODES_CONTENT_TYPE_JSON; - } else if (strstr(ext, ".css")) { + } else if (!strcmp(ext, ".css")) { content_type = MODES_CONTENT_TYPE_CSS; - } else if (strstr(ext, ".js")) { + } else if (!strcmp(ext, ".js")) { content_type = MODES_CONTENT_TYPE_JS; - } else if (strstr(ext, ".gif")) { + } else if (!strcmp(ext, ".gif")) { content_type = MODES_CONTENT_TYPE_GIF; } }