hsts: use Curl_fopen()
This commit is contained in:
parent
fab970a5d1
commit
d64115d7bb
22
lib/hsts.c
22
lib/hsts.c
@ -37,7 +37,7 @@
|
||||
#include "sendf.h"
|
||||
#include "strtoofft.h"
|
||||
#include "parsedate.h"
|
||||
#include "rand.h"
|
||||
#include "fopen.h"
|
||||
#include "rename.h"
|
||||
#include "strtoofft.h"
|
||||
|
||||
@ -356,8 +356,7 @@ CURLcode Curl_hsts_save(struct Curl_easy *data, struct hsts *h,
|
||||
struct Curl_llist_element *n;
|
||||
CURLcode result = CURLE_OK;
|
||||
FILE *out;
|
||||
char *tempstore;
|
||||
unsigned char randsuffix[9];
|
||||
char *tempstore = NULL;
|
||||
|
||||
if(!h)
|
||||
/* no cache activated */
|
||||
@ -371,17 +370,8 @@ CURLcode Curl_hsts_save(struct Curl_easy *data, struct hsts *h,
|
||||
/* marked as read-only, no file or zero length file name */
|
||||
goto skipsave;
|
||||
|
||||
if(Curl_rand_hex(data, randsuffix, sizeof(randsuffix)))
|
||||
return CURLE_FAILED_INIT;
|
||||
|
||||
tempstore = aprintf("%s.%s.tmp", file, randsuffix);
|
||||
if(!tempstore)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
out = fopen(tempstore, FOPEN_WRITETEXT);
|
||||
if(!out)
|
||||
result = CURLE_WRITE_ERROR;
|
||||
else {
|
||||
result = Curl_fopen(data, file, &out, &tempstore);
|
||||
if(!result) {
|
||||
fputs("# Your HSTS cache. https://curl.se/docs/hsts.html\n"
|
||||
"# This file was generated by libcurl! Edit at your own risk.\n",
|
||||
out);
|
||||
@ -393,10 +383,10 @@ CURLcode Curl_hsts_save(struct Curl_easy *data, struct hsts *h,
|
||||
break;
|
||||
}
|
||||
fclose(out);
|
||||
if(!result && Curl_rename(tempstore, file))
|
||||
if(!result && tempstore && Curl_rename(tempstore, file))
|
||||
result = CURLE_WRITE_ERROR;
|
||||
|
||||
if(result)
|
||||
if(result && tempstore)
|
||||
unlink(tempstore);
|
||||
}
|
||||
free(tempstore);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user