]> Nishi Git Mirror - tewi.git/commitdiff
fix stuff
authorNishi <nishi@nishi.boats>
Wed, 18 Sep 2024 20:58:17 +0000 (20:58 +0000)
committerNishi <nishi@nishi.boats>
Wed, 18 Sep 2024 20:58:17 +0000 (20:58 +0000)
git-svn-id: file:///raid/svn-personal/tewi/trunk@64 8739d7e6-ffea-ec47-b151-bdff447c6205

Server/http.c
Server/server.c

index c937fcf177e955243159abc640f3654f1c5cf92f..979d0903fbd24537e886968702229e836abb178c 100644 (file)
@@ -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];
index 1b3556625061babd3526a36e074f582b5525ae23..58a1ee5e97247a745234628cf79abe30b66ebcf1 100644 (file)
@@ -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);