mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
tests: Apply umask before calling mkstemp()
CID: #978660 Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
@@ -45,12 +45,14 @@ static void torture_sftp_read_blocking(void **state) {
|
|||||||
ssize_t byteswritten;
|
ssize_t byteswritten;
|
||||||
int fd;
|
int fd;
|
||||||
sftp_file file;
|
sftp_file file;
|
||||||
|
mode_t mask;
|
||||||
|
|
||||||
file = sftp_open(t->sftp, "/usr/bin/ssh", O_RDONLY, 0);
|
file = sftp_open(t->sftp, "/usr/bin/ssh", O_RDONLY, 0);
|
||||||
assert_non_null(file);
|
assert_non_null(file);
|
||||||
|
|
||||||
|
mask = umask(S_IRWXO | S_IRWXG);
|
||||||
fd = mkstemp(libssh_tmp_file);
|
fd = mkstemp(libssh_tmp_file);
|
||||||
|
umask(mask);
|
||||||
unlink(libssh_tmp_file);
|
unlink(libssh_tmp_file);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <libssh/libssh.h>
|
#include <libssh/libssh.h>
|
||||||
#include "torture.h"
|
#include "torture.h"
|
||||||
@@ -18,13 +20,16 @@ struct hostkey_state {
|
|||||||
|
|
||||||
static void setup(void **state) {
|
static void setup(void **state) {
|
||||||
struct hostkey_state *h;
|
struct hostkey_state *h;
|
||||||
|
mode_t mask;
|
||||||
|
|
||||||
h = malloc(sizeof(struct hostkey_state));
|
h = malloc(sizeof(struct hostkey_state));
|
||||||
assert_non_null(h);
|
assert_non_null(h);
|
||||||
|
|
||||||
h->hostkey_path = strdup("/tmp/libssh_hostkey_XXXXXX");
|
h->hostkey_path = strdup("/tmp/libssh_hostkey_XXXXXX");
|
||||||
|
|
||||||
|
mask = umask(S_IRWXO | S_IRWXG);
|
||||||
h->fd = mkstemp(h->hostkey_path);
|
h->fd = mkstemp(h->hostkey_path);
|
||||||
|
umask(mask);
|
||||||
assert_return_code(h->fd, errno);
|
assert_return_code(h->fd, errno);
|
||||||
close(h->fd);
|
close(h->fd);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user