Ensure we have a valid file handle in tus_file_mmap()

Unfortunately, I was not able to exactly reproduce the bug as
documented, but I am confident that this should fix it.

Fixes #1 (I hope)
parent 89fb7f3c
...@@ -473,7 +473,7 @@ static void ...@@ -473,7 +473,7 @@ static void
tus_file_mmap(struct tus_file_core *fcore) tus_file_mmap(struct tus_file_core *fcore)
{ {
struct tus_file_disk *fdisk; struct tus_file_disk *fdisk;
int prot = PROT_READ; int fd, prot = PROT_READ;
off_t len; off_t len;
CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC); CHECK_OBJ_NOTNULL(fcore, VMOD_TUS_FILE_CORE_MAGIC);
...@@ -489,6 +489,7 @@ tus_file_mmap(struct tus_file_core *fcore) ...@@ -489,6 +489,7 @@ tus_file_mmap(struct tus_file_core *fcore)
AZ(fcore->ptr); AZ(fcore->ptr);
AZ(fcore->len); AZ(fcore->len);
assert(fcore->ptr_type == TFCP_INVALID); assert(fcore->ptr_type == TFCP_INVALID);
fd = tus_file_open(fcore);
assert(fdisk->upload_offset > 0); assert(fdisk->upload_offset > 0);
assert(fdisk->upload_length > 0); assert(fdisk->upload_length > 0);
...@@ -498,11 +499,11 @@ tus_file_mmap(struct tus_file_core *fcore) ...@@ -498,11 +499,11 @@ tus_file_mmap(struct tus_file_core *fcore)
len += fdisk->upload_length; len += fdisk->upload_length;
prot |= PROT_WRITE; prot |= PROT_WRITE;
// XXX error handling // XXX error handling
AZ(fallocate(fcore->fd, (int)0, (off_t)0, len)); AZ(fallocate(fd, (int)0, (off_t)0, len));
} }
fcore->ptr = mmap(NULL, (size_t)fdisk->upload_length, prot, fcore->ptr = mmap(NULL, (size_t)fdisk->upload_length, prot,
MAP_SHARED | MAP_NORESERVE, fcore->fd, (off_t)header_size); MAP_SHARED | MAP_NORESERVE, fd, (off_t)header_size);
AN(fcore->ptr); AN(fcore->ptr);
fcore->ptr_type = (prot & PROT_WRITE) ? fcore->ptr_type = (prot & PROT_WRITE) ?
TFCP_MMAP_RW : TFCP_MMAP_RO; TFCP_MMAP_RW : TFCP_MMAP_RO;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment