Skip to content

Commit 872a0d9

Browse files
committed
tracing: Always use memcpy() in histogram add_to_key()
The add_to_key() function tests if the key is a string or some data. If it's a string it does some further calculations of the string size (still truncating it to the max size it can be), and calls strncpy(). If the key isn't as string it calls memcpy(). The interesting point is that both use the exact same parameters: strncpy(compound_key + key_field->offset, (char *)key, size); } else memcpy(compound_key + key_field->offset, key, size); As strncpy() is being used simply as a memcpy() for a string, and since strncpy() is deprecated, just call memcpy() for both memory and string keys. Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/20250403210637.1c477d4a@gandalf.local.home Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Reviewed-by: Tom Zanussi <zanussi@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 3e4b371 commit 872a0d9

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

kernel/trace/trace_events_hist.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5224,10 +5224,8 @@ static inline void add_to_key(char *compound_key, void *key,
52245224
/* ensure NULL-termination */
52255225
if (size > key_field->size - 1)
52265226
size = key_field->size - 1;
5227-
5228-
strncpy(compound_key + key_field->offset, (char *)key, size);
5229-
} else
5230-
memcpy(compound_key + key_field->offset, key, size);
5227+
}
5228+
memcpy(compound_key + key_field->offset, key, size);
52315229
}
52325230

52335231
static void

0 commit comments

Comments
 (0)