Browse Source

[core] fdevent_mkstemp_append() (shared)

personal/stbuehler/ci-build
Glenn Strauss 3 years ago
parent
commit
a78404cfbf
  1. 25
      src/chunk.c
  2. 22
      src/fdevent.c
  3. 1
      src/fdevent.h

25
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;

22
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;

1
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);

Loading…
Cancel
Save