numatop/0014-common-Use-memcpy-to-the-process-name-to-a-line.patch
Pingfan Liu c84d609f64 back port
Resolves: https://issues.redhat.com/browse/RHEL-24738
Resolves: https://issues.redhat.com/browse/RHEL-44824

Signed-off-by: Pingfan Liu <piliu@redhat.com>
2024-09-23 10:21:54 +08:00

52 lines
1.8 KiB
Diff

From e5b69a496bfd9f68ff7a6adbc2062bd875071f0f Mon Sep 17 00:00:00 2001
From: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Mon, 4 Mar 2024 23:03:02 +0100
Subject: [PATCH 14/32] common: Use memcpy() to the process name to a line
The copy will either collect the whole string, and potentially a little
more, but from a safe location, or a truncated string with a null char
guaranteed by the memset() call above.
This silences the stringop-truncation warning.
---
common/win.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/common/win.c b/common/win.c
index c06f42d..39909bc 100644
--- a/common/win.c
+++ b/common/win.c
@@ -355,8 +355,7 @@ topnproc_data_save(track_proc_t *proc, int intval, topnproc_line_t *line)
/*
* Cut off the process name if it's too long.
*/
- (void) strncpy(line->proc_name, proc->name, sizeof (line->proc_name));
- line->proc_name[WIN_PROCNAME_SIZE - 1] = 0;
+ memcpy(line->proc_name, proc->name, sizeof (line->proc_name) - 1);
line->pid = proc->pid;
line->nlwp = proc_nlwp(proc);
@@ -2892,8 +2891,7 @@ pqos_cmt_proc_data_save(track_proc_t *proc, track_lwp_t *lwp, int intval,
{
(void) memset(line, 0, sizeof (pqos_cmt_proc_line_t));
- (void) strncpy(line->proc_name, proc->name, sizeof (line->proc_name));
- line->proc_name[WIN_PROCNAME_SIZE - 1] = 0;
+ memcpy(line->proc_name, proc->name, sizeof (line->proc_name) - 1);
line->pid = proc->pid;
line->nlwp = proc_nlwp(proc);
@@ -3216,8 +3214,7 @@ pqos_mbm_proc_data_save(track_proc_t *proc, track_lwp_t *lwp, int intval,
{
(void) memset(line, 0, sizeof (pqos_mbm_proc_line_t));
- (void) strncpy(line->proc_name, proc->name, sizeof (line->proc_name));
- line->proc_name[WIN_PROCNAME_SIZE - 1] = 0;
+ memcpy(line->proc_name, proc->name, sizeof (line->proc_name) - 1);
line->pid = proc->pid;
line->nlwp = proc_nlwp(proc);
--
2.41.0