linux-user: Use glib malloc functions in load_symbols()
Switch to using the glib malloc functions in load_symbols(); this deals with a Coverity complaint about possible integer overflow calculating the allocation size with 'nsyms * sizeof(*syms)'. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
This commit is contained in:
		
							parent
							
								
									772034b63e
								
							
						
					
					
						commit
						0ef9ea290e
					
				@ -2111,19 +2111,19 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 found:
 | 
					 found:
 | 
				
			||||||
    /* Now know where the strtab and symtab are.  Snarf them.  */
 | 
					    /* Now know where the strtab and symtab are.  Snarf them.  */
 | 
				
			||||||
    s = malloc(sizeof(*s));
 | 
					    s = g_try_new(struct syminfo, 1);
 | 
				
			||||||
    if (!s) {
 | 
					    if (!s) {
 | 
				
			||||||
        goto give_up;
 | 
					        goto give_up;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    i = shdr[str_idx].sh_size;
 | 
					    i = shdr[str_idx].sh_size;
 | 
				
			||||||
    s->disas_strtab = strings = malloc(i);
 | 
					    s->disas_strtab = strings = g_try_malloc(i);
 | 
				
			||||||
    if (!strings || pread(fd, strings, i, shdr[str_idx].sh_offset) != i) {
 | 
					    if (!strings || pread(fd, strings, i, shdr[str_idx].sh_offset) != i) {
 | 
				
			||||||
        goto give_up;
 | 
					        goto give_up;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    i = shdr[sym_idx].sh_size;
 | 
					    i = shdr[sym_idx].sh_size;
 | 
				
			||||||
    syms = malloc(i);
 | 
					    syms = g_try_malloc(i);
 | 
				
			||||||
    if (!syms || pread(fd, syms, i, shdr[sym_idx].sh_offset) != i) {
 | 
					    if (!syms || pread(fd, syms, i, shdr[sym_idx].sh_offset) != i) {
 | 
				
			||||||
        goto give_up;
 | 
					        goto give_up;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -2157,7 +2157,7 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
 | 
				
			|||||||
       that we threw away.  Whether or not this has any effect on the
 | 
					       that we threw away.  Whether or not this has any effect on the
 | 
				
			||||||
       memory allocation depends on the malloc implementation and how
 | 
					       memory allocation depends on the malloc implementation and how
 | 
				
			||||||
       many symbols we managed to discard.  */
 | 
					       many symbols we managed to discard.  */
 | 
				
			||||||
    new_syms = realloc(syms, nsyms * sizeof(*syms));
 | 
					    new_syms = g_try_renew(struct elf_sym, syms, nsyms);
 | 
				
			||||||
    if (new_syms == NULL) {
 | 
					    if (new_syms == NULL) {
 | 
				
			||||||
        goto give_up;
 | 
					        goto give_up;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -2178,9 +2178,9 @@ static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
 | 
				
			|||||||
    return;
 | 
					    return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
give_up:
 | 
					give_up:
 | 
				
			||||||
    free(s);
 | 
					    g_free(s);
 | 
				
			||||||
    free(strings);
 | 
					    g_free(strings);
 | 
				
			||||||
    free(syms);
 | 
					    g_free(syms);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
 | 
					int load_elf_binary(struct linux_binprm *bprm, struct image_info *info)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user