Check-in [47ef170824]
Overview
Comment:Fixed segfault issue and updated to limit sendfile() size
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:47ef170824ca0327a37651aee692101032c28c3f
User & Date: rkeene on 2014-02-06 08:03:00
Other Links: manifest | tags
Context
2014-02-06
08:26
Added additional debugging regarding range computation check-in: c35e6a2d15 user: rkeene tags: trunk
08:03
Fixed segfault issue and updated to limit sendfile() size check-in: 47ef170824 user: rkeene tags: trunk
07:53
Added large file support check-in: abb8c966f2 user: rkeene tags: trunk
Changes

Modified filed.c from [5dd5b62c7d] to [107a3dbac4].

    11     11   #include <unistd.h>
    12     12   #include <string.h>
    13     13   #include <fcntl.h>
    14     14   #include <stdio.h>
    15     15   #include <errno.h>
    16     16   #include <time.h>
    17     17   
           18  +/* Compile time constants */
           19  +#define FILED_SENDFILE_MAX 16777215
           20  +
    18     21   /* Default values */
    19     22   #define MAX_FAILURE_COUNT 30
    20     23   #define PORT 8080
    21     24   #define THREAD_COUNT 10
    22     25   #define BIND_ADDR "::"
    23     26   #define CACHE_SIZE 8192
    24     27   
................................................................................
   378    381   	);
   379    382   }
   380    383   
   381    384   /* Handle a single request from a client */
   382    385   static void filed_handle_client(int fd, struct filed_http_request *request) {
   383    386   	struct filed_fileinfo *fileinfo;
   384    387   	ssize_t sendfile_ret;
   385         -	size_t sendfile_len, sendfile_sent;
          388  +	size_t sendfile_len, sendfile_sent, sendfile_size;
   386    389   	off_t sendfile_offset;
   387    390   	char *path;
   388    391   	char *date_current, date_current_b[64];
   389    392   	int http_code;
   390    393   	FILE *fp;
   391    394   
   392    395   	/* Determine current time */
................................................................................
   398    401   		close(fd);
   399    402   
   400    403   		return;
   401    404   	}
   402    405   
   403    406   	request = filed_get_http_request(fp, request);
   404    407   
   405         -	path = request->path;
   406         -
   407    408   	filed_log_msg("PROCESS_REPLY_START FD=... PATH=... RANGE_START=... RANGE_LENGTH=...");
   408    409   
   409         -	if (path == NULL) {
          410  +	if (request == NULL || request->path == NULL) {
   410    411   		filed_error_page(fp, date_current, 500);
   411    412   
   412    413   		filed_log_msg("PROCESS_REPLY_COMPLETE FD=... ERROR=500");
   413    414   
   414    415   		fclose(fp);
   415    416   
   416    417   		return;
   417    418   	}
          419  +
          420  +	path = request->path;
   418    421   
   419    422   	http_code = -1;
   420    423   
   421    424   	fileinfo = filed_open_file(path, &request->fileinfo);
   422    425   	if (fileinfo == NULL) {
   423    426   		filed_error_page(fp, date_current, 404);
   424    427   
................................................................................
   485    488   
   486    489   			filed_log_msg("SEND_START IFD=... OFD=... BYTES=...");
   487    490   
   488    491   			sendfile_offset = request->headers.range.offset;
   489    492   			sendfile_len = request->headers.range.length;
   490    493   			sendfile_sent = 0;
   491    494   			while (1) {
   492         -				sendfile_ret = sendfile(fd, fileinfo->fd, &sendfile_offset, sendfile_len);
          495  +				if (sendfile_len > FILED_SENDFILE_MAX) {
          496  +					sendfile_size = FILED_SENDFILE_MAX;
          497  +				} else {
          498  +					sendfile_size = sendfile_len;
          499  +				}
          500  +
          501  +				sendfile_ret = sendfile(fd, fileinfo->fd, &sendfile_offset, sendfile_size);
   493    502   				if (sendfile_ret <= 0) {
   494    503   #ifdef FILED_NONBLOCK_HTTP
   495    504   					if (errno == EAGAIN) {
   496    505   						sendfile_ret = 0;
   497    506   
   498    507   						while (1) {
   499    508   							select(fd + 1, &rfd, &wfd, NULL, NULL);