Avoid trying to mmap zero-length files.

Remove buf size limit in mmap case: prevented processing entire file.
This commit is contained in:
John-Mark Bell 2012-09-19 22:50:28 +01:00
parent d5e1616a45
commit c22fbf9377

View File

@ -256,7 +256,7 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx,
{
#ifdef HAVE_MMAP
fetch_msg msg;
char *buf;
char *buf = NULL;
size_t buf_size;
int fd; /**< The file descriptor of the object */
@ -279,10 +279,9 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx,
/* set buffer size */
buf_size = fdstat->st_size;
if (buf_size > FETCH_FILE_MAX_BUF_SIZE)
buf_size = FETCH_FILE_MAX_BUF_SIZE;
/* allocate the buffer storage */
if (buf_size > 0) {
buf = mmap(NULL, buf_size, PROT_READ, MAP_SHARED, fd, 0);
if (buf == MAP_FAILED) {
msg.type = FETCH_ERROR;
@ -291,6 +290,7 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx,
close(fd);
return;
}
}
/* fetch is going to be successful */
fetch_set_http_code(ctx->fetchh, 200);
@ -327,6 +327,7 @@ static void fetch_file_process_plain(struct fetch_file_context *ctx,
fetch_file_process_aborted:
if (buf != NULL)
munmap(buf, buf_size);
close(fd);
#else