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>
This commit is contained in:
Anderson Toshiyuki Sasaki
2018-11-19 13:45:36 +01:00
committed by Andreas Schneider
parent 78b1f0ead3
commit 77be4ce905
3 changed files with 15 additions and 21 deletions

View File

@@ -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)