From 025a2198a4282b22d6c168555610b256fe4a8a12 Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Thu, 2 Sep 2021 16:13:12 +0200 Subject: [PATCH] zdump/dfi_s390: Fix use of uninitialized stack value in mem_chunks_add_ext() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the while loop in mem_chunks_add_ext() is never executed, then the stack variable containing the dump segment header will never be initialized. clang's static code analyzer reports the following problem: $ make CC="clang --analyze" -C zdump dfi_s390.c:157:6: warning: Branch condition evaluates to a garbage value [core.uninitialized.Branch] if (!dump_segm.stop_marker) ^~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Alexander Egorenkov Reported-by: Marc Hartmayer Signed-off-by: Jan Höppner --- zdump/dfi_s390.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zdump/dfi_s390.c b/zdump/dfi_s390.c index dea672e4..73fabeab 100644 --- a/zdump/dfi_s390.c +++ b/zdump/dfi_s390.c @@ -119,7 +119,7 @@ static int mem_chunks_add(void) */ static int mem_chunks_add_ext(void) { - struct df_s390_dump_segm_hdr dump_segm; + struct df_s390_dump_segm_hdr dump_segm = { 0 }; u64 rc, off, old = 0, dump_size = 0; off = zg_seek(g.fh, DF_S390_HDR_SIZE, ZG_CHECK_NONE); @@ -148,14 +148,14 @@ static int mem_chunks_add_ext(void) if (dump_segm.stop_marker) break; } + /* Check if the last dump segment found */ + if (!dump_segm.stop_marker) + return -EINVAL; /* Add zero memory chunk at the end */ dfi_mem_chunk_add(old, l.hdr.mem_size - old, NULL, dfi_mem_chunk_read_zero, NULL); /* Set the actual size of the dump file */ dfi_attr_file_size_set(dump_size); - /* Check if the last dump segment found */ - if (!dump_segm.stop_marker) - return -EINVAL; /* Read and verify the end marker */ return read_s390_em(); }