From 13eb135280235ec07b45c8331e8cf35b4b04d143 Mon Sep 17 00:00:00 2001 From: Nishi Date: Wed, 18 Sep 2024 20:58:17 +0000 Subject: [PATCH] fix stuff git-svn-id: file:///raid/svn-personal/tewi/trunk@64 8739d7e6-ffea-ec47-b151-bdff447c6205 --- Server/http.c | 12 +++++++++++- Server/server.c | 26 ++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Server/http.c b/Server/http.c index c937fcf..979d090 100644 --- a/Server/http.c +++ b/Server/http.c @@ -32,6 +32,13 @@ void tw_free_request(struct tw_http_request* req) { } if(req->body != NULL) free(req->body); if(req->version != NULL) free(req->version); + + req->method = NULL; + req->path = NULL; + req->query = NULL; + req->headers = NULL; + req->body = NULL; + req->version = NULL; } int tw_http_parse(SSL* ssl, int sock, struct tw_http_request* req) { @@ -75,7 +82,10 @@ int tw_http_parse(SSL* ssl, int sock, struct tw_http_request* req) { } #endif int len = tw_read(ssl, sock, buffer, 512); - if(len <= 0) break; + if(len <= 0){ + bad = true; + break; + } int i; for(i = 0; i < len; i++) { char c = buffer[i]; diff --git a/Server/server.c b/Server/server.c index 1b35566..58a1ee5 100644 --- a/Server/server.c +++ b/Server/server.c @@ -428,21 +428,23 @@ void tw_server_pass(int sock, bool ssl, int port, SOCKADDR addr) { char* vhost = cm_strdup(config.hostname); int i; time_t cmtime = 0; - for(i = 0; req.headers[i] != NULL; i += 2) { - if(cm_strcaseequ(req.headers[i], "Host")) { - free(vhost); - vhost = cm_strdup(req.headers[i + 1]); - } else if(cm_strcaseequ(req.headers[i], "If-Modified-Since")) { - struct tm tm; - strptime(req.headers[i + 1], "%a, %d %b %Y %H:%M:%S GMT", &tm); + if(req.headers != NULL){ + for(i = 0; req.headers[i] != NULL; i += 2) { + if(cm_strcaseequ(req.headers[i], "Host")) { + free(vhost); + vhost = cm_strdup(req.headers[i + 1]); + } else if(cm_strcaseequ(req.headers[i], "If-Modified-Since")) { + struct tm tm; + strptime(req.headers[i + 1], "%a, %d %b %Y %H:%M:%S GMT", &tm); #ifdef __MINGW32__ - time_t t = 0; - struct tm* btm = localtime(&t); - cmtime = mktime(&tm); - cmtime -= (btm->tm_hour * 60 + btm->tm_min) * 60; + time_t t = 0; + struct tm* btm = localtime(&t); + cmtime = mktime(&tm); + cmtime -= (btm->tm_hour * 60 + btm->tm_min) * 60; #else - cmtime = timegm(&tm); + cmtime = timegm(&tm); #endif + } } } cm_log("Server", "Host is %s", vhost); -- 2.43.0