1
1

tests: use torture_create_temp_file() in torture_knownhosts_parsing

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
Anderson Toshiyuki Sasaki 2018-11-19 13:45:36 +01:00 коммит произвёл Andreas Schneider
родитель 78b1f0ead3
Коммит 77be4ce905
3 изменённых файлов: 15 добавлений и 21 удалений

Просмотреть файл

@ -1058,6 +1058,7 @@ char *torture_create_temp_file(const char *template)
goto free_prefix;
}
/* Remark: this function creates the file */
rc = GetTempFileNameA(tmp_dir_path, TEXT(prefix), 0, tmp_file_name);
if (rc == 0) {
goto free_prefix;

Просмотреть файл

@ -31,37 +31,29 @@ static int setup_knownhosts_file(void **state)
char *tmp_file = NULL;
size_t nwritten;
FILE *fp = NULL;
mode_t mask;
int fd;
int rc = 0;
tmp_file = strdup(TMP_FILE_NAME);
tmp_file = torture_create_temp_file(TMP_FILE_NAME);
assert_non_null(tmp_file);
*state = tmp_file;
mask = umask(S_IRWXO | S_IRWXG);
fd = mkstemp(tmp_file);
umask(mask);
assert_return_code(fd, errno);
fp = fdopen(fd, "w");
if (fp == NULL) {
close(fd);
return -1;
}
fp = fopen(tmp_file, "w");
assert_non_null(fp);
nwritten = fwrite(LOCALHOST_PATTERN_ED25519,
sizeof(char),
strlen(LOCALHOST_PATTERN_ED25519),
fp);
if (nwritten != strlen(LOCALHOST_PATTERN_ED25519)) {
fclose(fp);
return -1;
rc = -1;
goto close_fp;
}
nwritten = fwrite("\n", sizeof(char), 1, fp);
if (nwritten != 1) {
fclose(fp);
return -1;
rc = -1;
goto close_fp;
}
nwritten = fwrite(LOCALHOST_RSA_LINE,
@ -69,13 +61,14 @@ static int setup_knownhosts_file(void **state)
strlen(LOCALHOST_RSA_LINE),
fp);
if (nwritten != strlen(LOCALHOST_RSA_LINE)) {
fclose(fp);
return -1;
rc = -1;
goto close_fp;
}
close_fp:
fclose(fp);
return 0;
return rc;
}
static int teardown_knownhosts_file(void **state)

Просмотреть файл

@ -3,7 +3,7 @@
#include "torture.h"
#define LIBSSH_STATIC
const char template[] = "/tmp/temp_file_XXXXXX";
const char template[] = "temp_file_XXXXXX";
static int setup(void **state)
{