mirror of
https://github.com/curl/curl.git
synced 2026-07-26 12:37:16 +03:00
tests: replace strcpy() with curlx_strcopy()
Also: - examples/hsts-preload: apply the same change as it's based on lib1915 in tests. Make a local clone of `curlx_strcopy()`. Then drop the `_CRT_SECURE_NO_WARNINGS` hack, that's no longer necessary. - curl_setup.h: delete `strcpy()` from the `_CRT_SECURE_NO_WARNINGS` list. Closes #20076
This commit is contained in:
parent
66aec526fc
commit
436e67f65b
9 changed files with 43 additions and 30 deletions
|
|
@ -25,12 +25,6 @@
|
|||
* Preload domains to HSTS
|
||||
* </DESC>
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
#ifndef _CRT_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_WARNINGS /* for strcpy() */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
@ -51,6 +45,16 @@ struct state {
|
|||
int index;
|
||||
};
|
||||
|
||||
static void strcopy(char *dest, size_t dsize, const char *src, size_t slen)
|
||||
{
|
||||
if(slen < dsize) {
|
||||
memcpy(dest, src, slen);
|
||||
dest[slen] = 0;
|
||||
}
|
||||
else if(dsize)
|
||||
dest[0] = 0;
|
||||
}
|
||||
|
||||
/* "read" is from the point of the library, it wants data from us. One domain
|
||||
entry per invoke. */
|
||||
static CURLSTScode hstsread(CURL *curl, struct curl_hstsentry *e, void *userp)
|
||||
|
|
@ -62,10 +66,10 @@ static CURLSTScode hstsread(CURL *curl, struct curl_hstsentry *e, void *userp)
|
|||
host = preload_hosts[s->index].name;
|
||||
expire = preload_hosts[s->index++].exp;
|
||||
|
||||
if(host && (strlen(host) < e->namelen)) {
|
||||
strcpy(e->name, host);
|
||||
if(host) {
|
||||
strcopy(e->name, e->namelen, host, strlen(host));
|
||||
e->includeSubDomains = 0;
|
||||
strcpy(e->expire, expire);
|
||||
strcopy(e->expire, sizeof(e->expire), expire, strlen(expire));
|
||||
fprintf(stderr, "HSTS preload '%s' until '%s'\n", host, expire);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue