zdump/dfi_s390: Fix use of uninitialized stack value in mem_chunks_add_ext()

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 <egorenar@linux.ibm.com>
Reported-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Alexander Egorenkov
2021-09-02 16:13:12 +02:00
committed by Jan Höppner
parent 2b938b78aa
commit 025a2198a4

View File

@@ -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();
}