tests/server/util.c: remove use of strncpy

... and ban the function in code in this directory.

Closes #15213
This commit is contained in:
Daniel Stenberg 2024-10-09 15:56:28 +02:00
parent 08949637d5
commit 45b388fdc7
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
4 changed files with 62 additions and 54 deletions

View File

@ -49,6 +49,7 @@ path = [
"lib/vtls/.checksrc", "lib/vtls/.checksrc",
"src/.checksrc", "src/.checksrc",
"tests/libtest/.checksrc", "tests/libtest/.checksrc",
"tests/server/.checksrc",
] ]
SPDX-FileCopyrightText = "Daniel Stenberg, <daniel@haxx.se>, et al." SPDX-FileCopyrightText = "Daniel Stenberg, <daniel@haxx.se>, et al."
SPDX-License-Identifier = "curl" SPDX-License-Identifier = "curl"

1
tests/server/.checksrc Normal file
View File

@ -0,0 +1 @@
enable STRNCPY

View File

@ -50,7 +50,7 @@ AM_CPPFLAGS += -DCURL_NO_GETADDRINFO_OVERRIDE
# Makefile.inc provides neat definitions # Makefile.inc provides neat definitions
include Makefile.inc include Makefile.inc
EXTRA_DIST = base64.pl CMakeLists.txt EXTRA_DIST = base64.pl CMakeLists.txt .checksrc
CHECKSRC = $(CS_$(V)) CHECKSRC = $(CS_$(V))
CS_0 = @echo " RUN " $@; CS_0 = @echo " RUN " $@;

View File

@ -834,13 +834,19 @@ void restore_signal_handlers(bool keep_sigalrm)
#ifdef USE_UNIX_SOCKETS #ifdef USE_UNIX_SOCKETS
int bind_unix_socket(curl_socket_t sock, const char *unix_socket, int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
struct sockaddr_un *sau) { struct sockaddr_un *sau)
{
int error; int error;
int rc; int rc;
size_t len = strlen(unix_socket);
memset(sau, 0, sizeof(struct sockaddr_un)); memset(sau, 0, sizeof(struct sockaddr_un));
sau->sun_family = AF_UNIX; sau->sun_family = AF_UNIX;
strncpy(sau->sun_path, unix_socket, sizeof(sau->sun_path) - 1); if(len >= sizeof(sau->sun_path) - 1) {
logmsg("Too long unix socket domain path (%zd)", len);
return -1;
}
strcpy(sau->sun_path, unix_socket);
rc = bind(sock, (struct sockaddr*)sau, sizeof(struct sockaddr_un)); rc = bind(sock, (struct sockaddr*)sau, sizeof(struct sockaddr_un));
if(0 != rc && SOCKERRNO == EADDRINUSE) { if(0 != rc && SOCKERRNO == EADDRINUSE) {
struct_stat statbuf; struct_stat statbuf;