diff options
Diffstat (limited to 'libs/libcurl/src/hsts.c')
-rw-r--r-- | libs/libcurl/src/hsts.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/libs/libcurl/src/hsts.c b/libs/libcurl/src/hsts.c index baf308874a..9ccfa14905 100644 --- a/libs/libcurl/src/hsts.c +++ b/libs/libcurl/src/hsts.c @@ -40,6 +40,7 @@ #include "fopen.h"
#include "rename.h"
#include "share.h"
+#include "strdup.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
@@ -76,7 +77,7 @@ static time_t hsts_debugtime(void *unused) struct hsts *Curl_hsts_init(void)
{
- struct hsts *h = calloc(sizeof(struct hsts), 1);
+ struct hsts *h = calloc(1, sizeof(struct hsts));
if(h) {
Curl_llist_init(&h->list, NULL);
}
@@ -108,7 +109,7 @@ void Curl_hsts_cleanup(struct hsts **hp) static struct stsentry *hsts_entry(void)
{
- return calloc(sizeof(struct stsentry), 1);
+ return calloc(1, sizeof(struct stsentry));
}
static CURLcode hsts_create(struct hsts *h,
@@ -116,23 +117,30 @@ static CURLcode hsts_create(struct hsts *h, bool subdomains,
curl_off_t expires)
{
- struct stsentry *sts = hsts_entry();
+ struct stsentry *sts;
char *duphost;
size_t hlen;
+ DEBUGASSERT(h);
+ DEBUGASSERT(hostname);
+
+ hlen = strlen(hostname);
+ if(hlen && (hostname[hlen - 1] == '.'))
+ /* strip off any trailing dot */
+ --hlen;
+ if(!hlen)
+ /* no host name left */
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+
+ sts = hsts_entry();
if(!sts)
return CURLE_OUT_OF_MEMORY;
- duphost = strdup(hostname);
+ duphost = Curl_strndup(hostname, hlen);
if(!duphost) {
free(sts);
return CURLE_OUT_OF_MEMORY;
}
- hlen = strlen(duphost);
- if(duphost[hlen - 1] == '.')
- /* strip off trailing any dot */
- duphost[--hlen] = 0;
-
sts->host = duphost;
sts->expires = expires;
sts->includeSubDomains = subdomains;
@@ -564,7 +572,7 @@ CURLcode Curl_hsts_loadcb(struct Curl_easy *data, struct hsts *h) void Curl_hsts_loadfiles(struct Curl_easy *data)
{
- struct curl_slist *l = data->set.hstslist;
+ struct curl_slist *l = data->state.hstslist;
if(l) {
Curl_share_lock(data, CURL_LOCK_DATA_HSTS, CURL_LOCK_ACCESS_SINGLE);
|