Commit 6a087ac2 authored by Ihor Solodrai's avatar Ihor Solodrai Committed by Alexei Starovoitov
Browse files

selftests/bpf: Replace strcpy() calls with strscpy()

strcpy() does not perform bounds checking and is considered deprecated
[1]. Replace strcpy() calls with strscpy() defined in bpf_util.h.

[1] https://docs.kernel.org/process/deprecated.html#strcpy



Signed-off-by: default avatarIhor Solodrai <ihor.solodrai@linux.dev>
Link: https://lore.kernel.org/r/20260223190736.649171-3-ihor.solodrai@linux.dev


Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 63c49efc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -432,7 +432,7 @@ int make_sockaddr(int family, const char *addr_str, __u16 port,
		memset(addr, 0, sizeof(*sun));
		sun->sun_family = family;
		sun->sun_path[0] = 0;
		strcpy(sun->sun_path + 1, addr_str);
		strscpy(sun->sun_path + 1, addr_str, sizeof(sun->sun_path) - 1);
		if (len)
			*len = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(addr_str);
		return 0;
+1 −1
Original line number Diff line number Diff line
@@ -281,7 +281,7 @@ static void test_dctcp_fallback(void)
	dctcp_skel = bpf_dctcp__open();
	if (!ASSERT_OK_PTR(dctcp_skel, "dctcp_skel"))
		return;
	strcpy(dctcp_skel->rodata->fallback_cc, "cubic");
	strscpy(dctcp_skel->rodata->fallback_cc, "cubic");
	if (!ASSERT_OK(bpf_dctcp__load(dctcp_skel), "bpf_dctcp__load"))
		goto done;

+1 −1
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ void test_setget_sockopt(void)
	if (!ASSERT_OK_PTR(skel, "open skel"))
		goto done;

	strcpy(skel->rodata->veth, "binddevtest1");
	strscpy(skel->rodata->veth, "binddevtest1");
	skel->rodata->veth_ifindex = if_nametoindex("binddevtest1");
	if (!ASSERT_GT(skel->rodata->veth_ifindex, 0, "if_nametoindex"))
		goto done;
+1 −1
Original line number Diff line number Diff line
@@ -142,7 +142,7 @@ static int getsetsockopt(void)

	/* TCP_CONGESTION can extend the string */

	strcpy(buf.cc, "nv");
	strscpy(buf.cc, "nv");
	err = setsockopt(fd, SOL_TCP, TCP_CONGESTION, &buf, strlen("nv"));
	if (err) {
		log_err("Failed to call setsockopt(TCP_CONGESTION)");
+2 −2
Original line number Diff line number Diff line
@@ -24,9 +24,9 @@ static struct fixture *init_fixture(void)

	/* for no_alu32 and cpuv4 veristat is in parent folder */
	if (access("./veristat", F_OK) == 0)
		strcpy(fix->veristat, "./veristat");
		strscpy(fix->veristat, "./veristat");
	else if (access("../veristat", F_OK) == 0)
		strcpy(fix->veristat, "../veristat");
		strscpy(fix->veristat, "../veristat");
	else
		PRINT_FAIL("Can't find veristat binary");

Loading