1
1
/*
2
- * Copyright (c) 2003, 2014 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2003, 2019 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -210,6 +210,9 @@ static int open_file_from_debug_link(const char *name,
210
210
+ strlen (".debug/" )
211
211
+ strlen (debug_file_directory )
212
212
+ 2 );
213
+ if (debug_pathname == NULL ) {
214
+ return -1 ;
215
+ }
213
216
strcpy (debug_pathname , name );
214
217
char * last_slash = strrchr (debug_pathname , '/' );
215
218
if (last_slash == NULL ) {
@@ -279,6 +282,9 @@ build_id_to_debug_filename (size_t size, unsigned char *data)
279
282
280
283
filename = malloc (strlen (debug_file_directory ) + (sizeof "/.build-id/" - 1 ) + 1
281
284
+ 2 * size + (sizeof ".debug" - 1 ) + 1 );
285
+ if (filename == NULL ) {
286
+ return NULL ;
287
+ }
282
288
s = filename + sprintf (filename , "%s/.build-id/" , debug_file_directory );
283
289
if (size > 0 )
284
290
{
@@ -305,7 +311,9 @@ static struct symtab* build_symtab_from_build_id(Elf64_Nhdr *note)
305
311
= (unsigned char * )(note + 1 ) + note -> n_namesz ;
306
312
char * filename
307
313
= (build_id_to_debug_filename (note -> n_descsz , bytes ));
308
-
314
+ if (filename == NULL ) {
315
+ return NULL ;
316
+ }
309
317
fd = pathmap_open (filename );
310
318
if (fd >= 0 ) {
311
319
symtab = build_symtab_internal (fd , NULL , /* try_debuginfo */ false);
@@ -417,6 +425,10 @@ static struct symtab* build_symtab_internal(int fd, const char *filename, bool t
417
425
htab_sz = n * 1.25 ;
418
426
419
427
symtab -> hash_table = (struct hsearch_data * ) calloc (1 , sizeof (struct hsearch_data ));
428
+ if (symtab -> hash_table == NULL ) {
429
+ goto bad ;
430
+ }
431
+
420
432
rslt = hcreate_r (n , symtab -> hash_table );
421
433
// guarantee(rslt, "unexpected failure: hcreate_r");
422
434
@@ -426,11 +438,17 @@ static struct symtab* build_symtab_internal(int fd, const char *filename, bool t
426
438
// strings will not be destroyed by elf_end.
427
439
size = scn_cache [shdr -> sh_link ].c_shdr -> sh_size ;
428
440
symtab -> strs = (char * )malloc (size );
441
+ if (symtab -> strs == NULL ) {
442
+ goto bad ;
443
+ }
429
444
memcpy (symtab -> strs , scn_cache [shdr -> sh_link ].c_data , size );
430
445
431
446
// allocate memory for storing symbol offset and size;
432
447
symtab -> num_symbols = n ;
433
448
symtab -> symbols = (struct elf_symbol * )calloc (n , sizeof (struct elf_symbol ));
449
+ if (symtab -> symbols == NULL ) {
450
+ goto bad ;
451
+ }
434
452
435
453
// copy symbols info our symtab and enter them info the hash table
436
454
for (j = 0 ; j < n ; j ++ , syms ++ ) {
@@ -512,6 +530,11 @@ static struct symtab* build_symtab_internal(int fd, const char *filename, bool t
512
530
symtab = prev_symtab ;
513
531
}
514
532
}
533
+ goto quit ;
534
+
535
+ bad :
536
+ destroy_symtab (symtab );
537
+ symtab = NULL ;
515
538
516
539
quit :
517
540
if (shbuf ) free (shbuf );
0 commit comments