Skip to contentSkip to conversation

tracing: Replace deprecated strncpy() with strscpy() for string keys in hist triggers

PATCH In review Devaansh Kumar 2 participants 2 messages May 14, 2025 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing: Replace deprecated strncpy() with strscpy() for string keys in hist triggers

strncpy() is deprecated for NUL-terminated destination buffers and must be replaced by strscpy().

See issue: https://github.com/KSPP/linux/issues/90

---
 kernel/trace/trace_events_hist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +1 -1
index 1260c23cfa5f..90a4e486fba8 100644
@@ -5225,7 +5225,7 @@ static inline void add_to_key(char *compound_key, void *key,
 		if (size > key_field->size - 1)
 			size = key_field->size - 1;
 
-		strncpy(compound_key + key_field->offset, (char *)key, size);
+		strscpy(compound_key + key_field->offset, (char *)key, size);
 	} else
 		memcpy(compound_key + key_field->offset, key, size);
 }
Signature · 1 line
2.49.0
maintainer
#1 lore raw
Quoted 15 lines · On Thu, 15 May 2025 01:49:55 +0530 Devaansh Kumar <[email protected]>…

strncpy() is deprecated for NUL-terminated destination buffers and must be replaced by strscpy().

See issue: https://github.com/KSPP/linux/issues/90

---
 kernel/trace/trace_events_hist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +0 -0
index 1260c23cfa5f..90a4e486fba8 100644

kernel/trace/trace_events_hist.c static inline void add_to_key(char *compound_key, void *key, · line 5231

Quoted 8 lines
kernel/trace/trace_events_hist.c +1 -1
@@ -5225,7 +5225,7 @@ static inline void add_to_key(char *compound_key, void *key,
 		if (size > key_field->size - 1)
 			size = key_field->size - 1;
 
-		strncpy(compound_key + key_field->offset, (char *)key, size);
+		strscpy(compound_key + key_field->offset, (char *)key, size);
 	} else
 		memcpy(compound_key + key_field->offset, key, size);
 }

Incorrect, and this is already fixed in next (at least it's in my ftrace/for-next branch).

https://lore.kernel.org/[email protected]

-- Steve