Ticket #7742: uhttpd-disconnect-handling.patch

File uhttpd-disconnect-handling.patch, 2.7 KB (added by jow, 6 years ago)

Stricter return value handling

  • package/uhttpd/src/uhttpd-file.c

     
    9898} 
    9999 
    100100#define ensure_ret(x) \ 
    101         do { if( x < 0 ) return; } while(0) 
     101        do { if( x < 0 ) return -1; } while(0) 
    102102 
    103 static void uh_file_response_ok_hdrs(struct client *cl, struct http_request *req, struct stat *s) 
     103static int uh_file_response_ok_hdrs(struct client *cl, struct http_request *req, struct stat *s) 
    104104{ 
    105105        ensure_ret(uh_http_sendf(cl, NULL, "Connection: close\r\n")); 
    106106 
     
    110110                ensure_ret(uh_http_sendf(cl, NULL, "Last-Modified: %s\r\n", uh_file_unix2date(s->st_mtime))); 
    111111        } 
    112112 
    113         ensure_ret(uh_http_sendf(cl, NULL, "Date: %s\r\n", uh_file_unix2date(time(NULL)))); 
     113        return uh_http_sendf(cl, NULL, "Date: %s\r\n", uh_file_unix2date(time(NULL))); 
    114114} 
    115115 
    116 static void uh_file_response_200(struct client *cl, struct http_request *req, struct stat *s) 
     116static int uh_file_response_200(struct client *cl, struct http_request *req, struct stat *s) 
    117117{ 
    118118        ensure_ret(uh_http_sendf(cl, NULL, "HTTP/%.1f 200 OK\r\n", req->version)); 
    119         uh_file_response_ok_hdrs(cl, req, s); 
     119        return uh_file_response_ok_hdrs(cl, req, s); 
    120120} 
    121121 
    122 static void uh_file_response_304(struct client *cl, struct http_request *req, struct stat *s) 
     122static int uh_file_response_304(struct client *cl, struct http_request *req, struct stat *s) 
    123123{ 
    124124        ensure_ret(uh_http_sendf(cl, NULL, "HTTP/%.1f 304 Not Modified\r\n", req->version)); 
    125         uh_file_response_ok_hdrs(cl, req, s); 
     125        return uh_file_response_ok_hdrs(cl, req, s); 
    126126} 
    127127 
    128 static void uh_file_response_412(struct client *cl, struct http_request *req) 
     128static int uh_file_response_412(struct client *cl, struct http_request *req) 
    129129{ 
    130         ensure_ret(uh_http_sendf(cl, NULL, 
     130        return uh_http_sendf(cl, NULL, 
    131131                "HTTP/%.1f 412 Precondition Failed\r\n" 
    132                 "Connection: close\r\n", req->version)); 
     132                "Connection: close\r\n", req->version); 
    133133} 
    134134 
    135135static int uh_file_if_match(struct client *cl, struct http_request *req, struct stat *s) 
     
    350350                        uh_file_if_none_match(cl, req, &pi->stat) 
    351351                ) { 
    352352                        /* write status */ 
    353                         uh_file_response_200(cl, req, &pi->stat); 
     353                        ensure_out(uh_file_response_200(cl, req, &pi->stat)); 
    354354 
    355355                        ensure_out(uh_http_sendf(cl, NULL, "Content-Type: %s\r\n", uh_file_mime_lookup(pi->name))); 
    356356                        ensure_out(uh_http_sendf(cl, NULL, "Content-Length: %i\r\n", pi->stat.st_size)); 
     
    385385        else if( (pi->stat.st_mode & S_IFDIR) && !cl->server->conf->no_dirlists ) 
    386386        { 
    387387                /* write status */ 
    388                 uh_file_response_200(cl, req, NULL); 
     388                ensure_out(uh_file_response_200(cl, req, NULL)); 
    389389 
    390390                if( req->version > 1.0 ) 
    391391                        ensure_out(uh_http_send(cl, NULL, "Transfer-Encoding: chunked\r\n", -1));