From 23503883babccc578ddde4a5b9a4a6d2cd020320 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Fri, 28 Oct 2016 14:05:07 -0400 Subject: [PATCH] [core] fix potential streaming tempfile corruption (fixes #2760) set O_APPEND after mkstemp() in chunk.c (mkostemp() is not as portable) (also set FD_CLOEXEC to avoid potentially leaking open tempfiles to CGI) (thx dieter.ro for helping track this down) x-ref: https://redmine.lighttpd.net/boards/3/topics/6884 "potential tempfile corruption when streaming response" https://redmine.lighttpd.net/issues/2760 --- src/chunk.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/chunk.c b/src/chunk.c index 253185fb..91b3999a 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -480,6 +480,9 @@ static chunk *chunkqueue_get_append_tempfile(chunkqueue *cq) { return NULL; } + fd_close_on_exec(fd); + (void)fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_APPEND); + c = chunkqueue_get_unused_chunk(cq); c->type = FILE_CHUNK; c->file.fd = fd; -- 2.11.4.GIT