public inbox for linux-kernel-mentees@lists.linux-foundation.org
 help / color / mirror / Atom feed
* [PATCH] libbpf: Replace strcpy() with memcpy() in bpf_object__new()
@ 2025-07-17 11:59 Suchit Karunakaran
  2025-07-17 16:49 ` Yonghong Song
  2025-07-17 17:19 ` Andrii Nakryiko
  0 siblings, 2 replies; 10+ messages in thread
From: Suchit Karunakaran @ 2025-07-17 11:59 UTC (permalink / raw)
  To: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, bpf
  Cc: skhan, linux-kernel-mentees, linux-kernel, Suchit Karunakaran

Replace the unsafe strcpy() call with memcpy() when copying the path
into the bpf_object structure. Since the memory is pre-allocated to
exactly strlen(path) + 1 bytes and the length is already known, memcpy()
is safer than strcpy().

Signed-off-by: Suchit Karunakaran <suchitkarunakaran@gmail.com>
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 52e353368f58..279f226dd965 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1495,7 +1495,7 @@ static struct bpf_object *bpf_object__new(const char *path,
 		return ERR_PTR(-ENOMEM);
 	}
 
-	strcpy(obj->path, path);
+	memcpy(obj->path, path, strlen(path) + 1);
 	if (obj_name) {
 		libbpf_strlcpy(obj->name, obj_name, sizeof(obj->name));
 	} else {
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-07-18 16:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-17 11:59 [PATCH] libbpf: Replace strcpy() with memcpy() in bpf_object__new() Suchit Karunakaran
2025-07-17 16:49 ` Yonghong Song
2025-07-17 16:59   ` Suchit K
2025-07-17 17:09     ` Greg KH
2025-07-17 17:20       ` Suchit K
2025-07-17 17:19 ` Andrii Nakryiko
2025-07-17 17:25   ` Suchit K
2025-07-17 17:33   ` Suchit K
2025-07-18 15:39     ` Andrii Nakryiko
2025-07-18 16:18       ` Suchit K

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox