[Sound-open-firmware] [PATCH] trace: don't copy uninitialized field from dma_sw_elem parameter

Pierre-Louis Bossart pierre-louis.bossart at linux.intel.com
Fri Jan 19 23:33:14 CET 2018


Coverity issue: 254842 Uninitialized scalar variable
The variable will contain an arbitrary value left from earlier
computations.

In parse_page_descriptors: Use of an uninitialized variable (CWE-457)
The elem.src variable is not initialized, but in
dma_trace_host_buffer() the code reads this initialized value.

Break

	*e = *elem;

in
	e->dest = elem->dest;
	e->size = elem->size;

to only access relevant fields.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart at linux.intel.com>
---
 src/lib/dma-trace.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/lib/dma-trace.c b/src/lib/dma-trace.c
index 7569d5d..429c7b6 100644
--- a/src/lib/dma-trace.c
+++ b/src/lib/dma-trace.c
@@ -185,7 +185,10 @@ int dma_trace_host_buffer(struct dma_trace_data *d, struct dma_sg_elem *elem,
 	if (e == NULL)
 		return -ENOMEM;
 
-	*e = *elem;
+	/* copy fields - excluding possibly non-initialized elem->src */
+	e->dest = elem->dest;
+	e->size = elem->size;
+
 	d->host_size = host_size;
 
 	list_item_append(&e->list, &d->config.elem_list);
-- 
2.14.1



More information about the Sound-open-firmware mailing list