summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/chunk.c25
-rw-r--r--src/fdevent.c22
-rw-r--r--src/fdevent.h1
3 files changed, 25 insertions, 23 deletions
diff --git a/src/chunk.c b/src/chunk.c
index c61afeb..f942fcf 100644
--- a/src/chunk.c
+++ b/src/chunk.c
@@ -524,21 +524,10 @@ static chunk *chunkqueue_get_append_tempfile(server *srv, chunkqueue *cq) {
buffer_copy_buffer(template, ds->value);
buffer_append_path_len(template, CONST_STR_LEN("lighttpd-upload-XXXXXX"));
-
- #ifdef __COVERITY__
- /* POSIX-2008 requires mkstemp create file with 0600 perms */
- umask(0600);
- #endif
- /* coverity[secure_temp : FALSE] */
- if (-1 != (fd = mkstemp(template->ptr))) break;
+ if (-1 != (fd = fdevent_mkstemp_append(template->ptr))) break;
}
} else {
- #ifdef __COVERITY__
- /* POSIX-2008 requires mkstemp create file with 0600 perms */
- umask(0600);
- #endif
- /* coverity[secure_temp : FALSE] */
- fd = mkstemp(template->ptr);
+ fd = fdevent_mkstemp_append(template->ptr);
}
if (fd < 0) {
@@ -551,16 +540,6 @@ static chunk *chunkqueue_get_append_tempfile(server *srv, chunkqueue *cq) {
return NULL;
}
- if (0 != fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_APPEND)) {
- /* (should not happen; fd is regular file) */
- log_error_write(srv, __FILE__, __LINE__, "sbs",
- "fcntl():", template, strerror(errno));
- close(fd);
- buffer_free(template);
- return NULL;
- }
- fdevent_setfd_cloexec(fd);
-
c = chunkqueue_append_file_chunk(cq, template, 0, 0);
c->file.fd = fd;
c->file.is_temp = 1;
diff --git a/src/fdevent.c b/src/fdevent.c
index bd19ec6..47f30ef 100644
--- a/src/fdevent.c
+++ b/src/fdevent.c
@@ -550,6 +550,28 @@ int fdevent_open_dirname(char *path, int symlinks) {
}
+int fdevent_mkstemp_append(char *path) {
+ #ifdef __COVERITY__
+ /* POSIX-2008 requires mkstemp create file with 0600 perms */
+ umask(0600);
+ #endif
+ /* coverity[secure_temp : FALSE] */
+ const int fd = mkstemp(path);
+ if (fd < 0) return fd;
+
+ if (0 != fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_APPEND)) {
+ /* (should not happen; fd is regular file) */
+ int errnum = errno;
+ close(fd);
+ errno = errnum;
+ return -1;
+ }
+
+ fdevent_setfd_cloexec(fd);
+ return fd;
+}
+
+
int fdevent_accept_listenfd(int listenfd, struct sockaddr *addr, size_t *addrlen) {
int fd;
socklen_t len = (socklen_t) *addrlen;
diff --git a/src/fdevent.h b/src/fdevent.h
index ba5db63..107293c 100644
--- a/src/fdevent.h
+++ b/src/fdevent.h
@@ -80,6 +80,7 @@ int fdevent_fcntl_set_nb_cloexec_sock(fdevents *ev, int fd);
int fdevent_socket_cloexec(int domain, int type, int protocol);
int fdevent_socket_nb_cloexec(int domain, int type, int protocol);
int fdevent_open_cloexec(const char *pathname, int symlinks, int flags, mode_t mode);
+int fdevent_mkstemp_append(char *path);
struct sockaddr;
int fdevent_accept_listenfd(int listenfd, struct sockaddr *addr, size_t *addrlen);