]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
xen/livepatch: Use zeroed memory allocations for arrays
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 22 Jun 2017 17:55:31 +0000 (18:55 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 23 Jun 2017 14:00:37 +0000 (15:00 +0100)
Each of these arrays is sparse.  Use zeroed allocations to cause uninitialised
array elements to contain deterministic values, most importantly for the
embedded pointers.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> [x86 and arm32]
Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
xen/common/livepatch.c
xen/common/livepatch_elf.c

index df67a1aa2c243874a2605e8a52f391662a8589ca..66d532db141253b67c53e03625aca7ca30390dff 100644 (file)
@@ -771,8 +771,8 @@ static int build_symbol_table(struct payload *payload,
         }
     }
 
-    symtab = xmalloc_array(struct livepatch_symbol, nsyms);
-    strtab = xmalloc_array(char, strtab_len);
+    symtab = xzalloc_array(struct livepatch_symbol, nsyms);
+    strtab = xzalloc_array(char, strtab_len);
 
     if ( !strtab || !symtab )
     {
index c4a9633078434630c922c1f1291295d0767d5b9d..b69e2718dd2244c3c50aeb2cd773ff21c9b22c79 100644 (file)
@@ -52,7 +52,7 @@ static int elf_resolve_sections(struct livepatch_elf *elf, const void *data)
     int rc;
 
     /* livepatch_elf_load sanity checked e_shnum. */
-    sec = xmalloc_array(struct livepatch_elf_sec, elf->hdr->e_shnum);
+    sec = xzalloc_array(struct livepatch_elf_sec, elf->hdr->e_shnum);
     if ( !sec )
     {
         dprintk(XENLOG_ERR, LIVEPATCH"%s: Could not allocate memory for section table!\n",
@@ -225,7 +225,7 @@ static int elf_get_sym(struct livepatch_elf *elf, const void *data)
     /* No need to check values as elf_resolve_sections did it. */
     nsym = symtab_sec->sec->sh_size / symtab_sec->sec->sh_entsize;
 
-    sym = xmalloc_array(struct livepatch_elf_sym, nsym);
+    sym = xzalloc_array(struct livepatch_elf_sym, nsym);
     if ( !sym )
     {
         dprintk(XENLOG_ERR, LIVEPATCH "%s: Could not allocate memory for symbols\n",