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:
Viktor Szakats 2025-12-23 11:59:59 +01:00
parent 66aec526fc
commit 436e67f65b
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
9 changed files with 43 additions and 30 deletions

View file

@ -391,19 +391,19 @@ int getpart(char **outbuf, size_t *outlen,
if(STATE_OUTSIDE == state) {
/* outermost element (<testcase>) */
strcpy(curouter, ptag);
curlx_strcopy(curouter, sizeof(curouter), ptag, strlen(ptag));
state = STATE_OUTER;
continue;
}
else if(STATE_OUTER == state) {
/* start of a main section */
strcpy(curmain, ptag);
curlx_strcopy(curmain, sizeof(curmain), ptag, strlen(ptag));
state = STATE_INMAIN;
continue;
}
else if(STATE_INMAIN == state) {
/* start of a sub section */
strcpy(cursub, ptag);
curlx_strcopy(cursub, sizeof(cursub), ptag, strlen(ptag));
state = STATE_INSUB;
if(!strcmp(curmain, main) && !strcmp(cursub, sub)) {
/* start of wanted part */

View file

@ -101,9 +101,12 @@ static void socksd_resetdefaults(void)
s_config.reqcmd = CONFIG_REQCMD;
s_config.connectrep = CONFIG_CONNECTREP;
s_config.port = CONFIG_PORT;
strcpy(s_config.addr, CONFIG_ADDR);
strcpy(s_config.user, "user");
strcpy(s_config.password, "password");
curlx_strcopy(s_config.addr, sizeof(s_config.addr),
CONFIG_ADDR, strlen(CONFIG_ADDR));
curlx_strcopy(s_config.user, sizeof(s_config.user),
"user", strlen("user"));
curlx_strcopy(s_config.password, sizeof(s_config.password),
"password", strlen("password"));
}
static void socksd_getconfig(void)
@ -141,7 +144,8 @@ static void socksd_getconfig(void)
}
}
else if(!strcmp(key, "backend")) {
strcpy(s_config.addr, value);
curlx_strcopy(s_config.addr, sizeof(s_config.addr),
value, strlen(value));
logmsg("backend [%s] set", s_config.addr);
}
else if(!strcmp(key, "backendport")) {
@ -152,11 +156,13 @@ static void socksd_getconfig(void)
}
}
else if(!strcmp(key, "user")) {
strcpy(s_config.user, value);
curlx_strcopy(s_config.user, sizeof(s_config.user),
value, strlen(value));
logmsg("user [%s] set", s_config.user);
}
else if(!strcmp(key, "password")) {
strcpy(s_config.password, value);
curlx_strcopy(s_config.password, sizeof(s_config.password),
value, strlen(value));
logmsg("password [%s] set", s_config.password);
}
/* Methods:

View file

@ -694,7 +694,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
logmsg("Too long unix socket domain path (%zd)", len);
return -1;
}
strcpy(sau->sun_path, unix_socket);
curlx_strcopy(sau->sun_path, sizeof(sau->sun_path), unix_socket, len);
rc = bind(sock, (struct sockaddr *)sau, sizeof(struct sockaddr_un));
if(rc && SOCKERRNO == SOCKEADDRINUSE) {
struct_stat statbuf;