View | Details | Raw Unified | Return to bug 17531 | Differences between
and this patch

Collapse All | Expand All

(-)a/binutils/readelf.c (-46 / +127 lines)
Lines 4104-4124 process_file_header (void) Link Here
4104
  return 1;
4104
  return 1;
4105
}
4105
}
4106
4106
4107
4107
static bfd_boolean
4108
static int
4109
get_32bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
4108
get_32bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
4110
{
4109
{
4111
  Elf32_External_Phdr * phdrs;
4110
  Elf32_External_Phdr * phdrs;
4112
  Elf32_External_Phdr * external;
4111
  Elf32_External_Phdr * external;
4113
  Elf_Internal_Phdr *   internal;
4112
  Elf_Internal_Phdr *   internal;
4114
  unsigned int i;
4113
  unsigned int i;
4114
  unsigned int size = elf_header.e_phentsize;
4115
  unsigned int num  = elf_header.e_phnum;
4116
4117
  /* PR binutils/17531: Cope with unexpected section header sizes.  */
4118
  if (size == 0 || num == 0)
4119
    return FALSE;
4120
  if (size < sizeof * phdrs)
4121
    {
4122
      error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
4123
      return FALSE;
4124
    }
4125
  if (size > sizeof * phdrs)
4126
    warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
4115
4127
4116
  phdrs = (Elf32_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
4128
  phdrs = (Elf32_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
4117
                                            elf_header.e_phentsize,
4129
                                            size, num, _("program headers"));
4118
                                            elf_header.e_phnum,
4130
  if (phdrs == NULL)
4119
                                            _("program headers"));
4131
    return FALSE;
4120
  if (!phdrs)
4121
    return 0;
4122
4132
4123
  for (i = 0, internal = pheaders, external = phdrs;
4133
  for (i = 0, internal = pheaders, external = phdrs;
4124
       i < elf_header.e_phnum;
4134
       i < elf_header.e_phnum;
Lines 4135-4158 get_32bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders) Link Here
4135
    }
4145
    }
4136
4146
4137
  free (phdrs);
4147
  free (phdrs);
4138
4148
  return TRUE;
4139
  return 1;
4140
}
4149
}
4141
4150
4142
static int
4151
static bfd_boolean
4143
get_64bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
4152
get_64bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders)
4144
{
4153
{
4145
  Elf64_External_Phdr * phdrs;
4154
  Elf64_External_Phdr * phdrs;
4146
  Elf64_External_Phdr * external;
4155
  Elf64_External_Phdr * external;
4147
  Elf_Internal_Phdr *   internal;
4156
  Elf_Internal_Phdr *   internal;
4148
  unsigned int i;
4157
  unsigned int i;
4158
  unsigned int size = elf_header.e_phentsize;
4159
  unsigned int num  = elf_header.e_phnum;
4160
4161
  /* PR binutils/17531: Cope with unexpected section header sizes.  */
4162
  if (size == 0 || num == 0)
4163
    return FALSE;
4164
  if (size < sizeof * phdrs)
4165
    {
4166
      error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n"));
4167
      return FALSE;
4168
    }
4169
  if (size > sizeof * phdrs)
4170
    warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n"));
4149
4171
4150
  phdrs = (Elf64_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
4172
  phdrs = (Elf64_External_Phdr *) get_data (NULL, file, elf_header.e_phoff,
4151
                                            elf_header.e_phentsize,
4173
                                            size, num, _("program headers"));
4152
                                            elf_header.e_phnum,
4153
                                            _("program headers"));
4154
  if (!phdrs)
4174
  if (!phdrs)
4155
    return 0;
4175
    return FALSE;
4156
4176
4157
  for (i = 0, internal = pheaders, external = phdrs;
4177
  for (i = 0, internal = pheaders, external = phdrs;
4158
       i < elf_header.e_phnum;
4178
       i < elf_header.e_phnum;
Lines 4169-4176 get_64bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders) Link Here
4169
    }
4189
    }
4170
4190
4171
  free (phdrs);
4191
  free (phdrs);
4172
4192
  return TRUE;
4173
  return 1;
4174
}
4193
}
4175
4194
4176
/* Returns 1 if the program headers were read into `program_headers'.  */
4195
/* Returns 1 if the program headers were read into `program_headers'.  */
Lines 6903-6908 get_unwind_section_word (struct arm_unw_aux_info * aux, Link Here
6903
  unsigned int word;
6922
  unsigned int word;
6904
  bfd_boolean wrapped;
6923
  bfd_boolean wrapped;
6905
6924
6925
  if (sec == NULL || arm_sec == NULL)
6926
    return FALSE;
6927
6906
  addr->section = SHN_UNDEF;
6928
  addr->section = SHN_UNDEF;
6907
  addr->offset = 0;
6929
  addr->offset = 0;
6908
6930
Lines 6958-6963 get_unwind_section_word (struct arm_unw_aux_info * aux, Link Here
6958
  if (arm_sec->data == NULL)
6980
  if (arm_sec->data == NULL)
6959
    return FALSE;
6981
    return FALSE;
6960
6982
6983
  /* If the offset is invalid then fail.  */
6984
  if (word_offset > sec->sh_size - 4)
6985
    return FALSE;
6986
6961
  /* Get the word at the required offset.  */
6987
  /* Get the word at the required offset.  */
6962
  word = byte_get (arm_sec->data + word_offset, 4);
6988
  word = byte_get (arm_sec->data + word_offset, 4);
6963
6989
Lines 9585-9591 get_symbol_index_type (unsigned int type) Link Here
9585
      else if (type >= SHN_LORESERVE)
9611
      else if (type >= SHN_LORESERVE)
9586
	sprintf (buff, "RSV[0x%04x]", type & 0xffff);
9612
	sprintf (buff, "RSV[0x%04x]", type & 0xffff);
9587
      else if (type >= elf_header.e_shnum)
9613
      else if (type >= elf_header.e_shnum)
9588
	sprintf (buff, "bad section index[%3d]", type);
9614
	sprintf (buff, _("bad section index[%3d]"), type);
9589
      else
9615
      else
9590
	sprintf (buff, "%3d", type);
9616
	sprintf (buff, "%3d", type);
9591
      break;
9617
      break;
Lines 9637-9648 print_dynamic_symbol (bfd_vma si, unsigned long hn) Link Here
9637
  Elf_Internal_Sym * psym;
9663
  Elf_Internal_Sym * psym;
9638
  int n;
9664
  int n;
9639
9665
9640
  psym = dynamic_symbols + si;
9641
9642
  n = print_vma (si, DEC_5);
9666
  n = print_vma (si, DEC_5);
9643
  if (n < 5)
9667
  if (n < 5)
9644
    fputs (&"     "[n], stdout);
9668
    fputs (&"     "[n], stdout);
9645
  printf (" %3lu: ", hn);
9669
  printf (" %3lu: ", hn);
9670
9671
  if (dynamic_symbols == NULL || si >= num_dynamic_syms)
9672
    {
9673
      printf (_("<No info available>\n"));
9674
      return;
9675
    }
9676
9677
  psym = dynamic_symbols + si;
9646
  print_vma (psym->st_value, LONG_HEX);
9678
  print_vma (psym->st_value, LONG_HEX);
9647
  putchar (' ');
9679
  putchar (' ');
9648
  print_vma (psym->st_size, DEC_5);
9680
  print_vma (psym->st_size, DEC_5);
Lines 10313-10318 process_syminfo (FILE * file ATTRIBUTE_UNUSED) Link Here
10313
      unsigned short int flags = dynamic_syminfo[i].si_flags;
10345
      unsigned short int flags = dynamic_syminfo[i].si_flags;
10314
10346
10315
      printf ("%4d: ", i);
10347
      printf ("%4d: ", i);
10348
      assert (i <  num_dynamic_syms);
10316
      if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
10349
      if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
10317
	print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
10350
	print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
10318
      else
10351
      else
Lines 12426-12431 display_raw_attribute (unsigned char * p, unsigned char * end) Link Here
12426
  unsigned long addr = 0;
12459
  unsigned long addr = 0;
12427
  size_t bytes = end - p;
12460
  size_t bytes = end - p;
12428
12461
12462
  assert (end > p);
12429
  while (bytes)
12463
  while (bytes)
12430
    {
12464
    {
12431
      int j;
12465
      int j;
Lines 12577-12582 process_attributes (FILE * file, Link Here
12577
	      bfd_boolean public_section;
12611
	      bfd_boolean public_section;
12578
	      bfd_boolean gnu_section;
12612
	      bfd_boolean gnu_section;
12579
12613
12614
	      if (len <= 4)
12615
		{
12616
		  error (_("Tag section ends prematurely\n"));
12617
		  break;
12618
		}
12580
	      section_len = byte_get (p, 4);
12619
	      section_len = byte_get (p, 4);
12581
	      p += 4;
12620
	      p += 4;
12582
12621
Lines 12611-12622 process_attributes (FILE * file, Link Here
12611
12650
12612
	      p += namelen;
12651
	      p += namelen;
12613
	      section_len -= namelen;
12652
	      section_len -= namelen;
12653
12614
	      while (section_len > 0)
12654
	      while (section_len > 0)
12615
		{
12655
		{
12616
		  int tag = *(p++);
12656
		  int tag;
12617
		  int val;
12657
		  int val;
12618
		  bfd_vma size;
12658
		  bfd_vma size;
12619
12659
12660
		  /* PR binutils/17531: Safe handling of corrupt files.  */
12661
		  if (section_len < 6)
12662
		    {
12663
		      error (_("Unused bytes at end of section\n"));
12664
		      section_len = 0;
12665
		      break;
12666
		    }
12667
12668
		  tag = *(p++);
12620
		  size = byte_get (p, 4);
12669
		  size = byte_get (p, 4);
12621
		  if (size > section_len)
12670
		  if (size > section_len)
12622
		    {
12671
		    {
Lines 12624-12629 process_attributes (FILE * file, Link Here
12624
			      (unsigned) size, (unsigned) section_len);
12673
			      (unsigned) size, (unsigned) section_len);
12625
		      size = section_len;
12674
		      size = section_len;
12626
		    }
12675
		    }
12676
		  /* PR binutils/17531: Safe handling of corrupt files.  */
12677
		  if (size < 6)
12678
		    {
12679
		      error (_("Bad subsection length (%u < 6)\n"),
12680
			      (unsigned) size);
12681
		      section_len = 0;
12682
		      break;
12683
		    }
12627
12684
12628
		  section_len -= size;
12685
		  section_len -= size;
12629
		  end = p + size - 1;
12686
		  end = p + size - 1;
Lines 13349-13363 process_mips_specific (FILE * file) Link Here
13349
13406
13350
      for (cnt = 0; cnt < conflictsno; ++cnt)
13407
      for (cnt = 0; cnt < conflictsno; ++cnt)
13351
	{
13408
	{
13352
	  Elf_Internal_Sym * psym = & dynamic_symbols[iconf[cnt]];
13353
13354
	  printf ("%5lu: %8lu  ", (unsigned long) cnt, iconf[cnt]);
13409
	  printf ("%5lu: %8lu  ", (unsigned long) cnt, iconf[cnt]);
13355
	  print_vma (psym->st_value, FULL_HEX);
13410
13356
	  putchar (' ');
13411
	  if (iconf[cnt] >= num_dynamic_syms)
13357
	  if (VALID_DYNAMIC_NAME (psym->st_name))
13412
	    printf (_("<corrupt symbol index>"));
13358
	    print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
13359
	  else
13413
	  else
13360
	    printf (_("<corrupt: %14ld>"), psym->st_name);
13414
	    {
13415
	      Elf_Internal_Sym * psym;
13416
13417
	      psym = & dynamic_symbols[iconf[cnt]];
13418
	      print_vma (psym->st_value, FULL_HEX);
13419
	      putchar (' ');
13420
	      if (VALID_DYNAMIC_NAME (psym->st_name))
13421
		print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
13422
	      else
13423
		printf (_("<corrupt: %14ld>"), psym->st_name);
13424
	    }
13361
	  putchar ('\n');
13425
	  putchar ('\n');
13362
	}
13426
	}
13363
13427
Lines 13432-13452 process_mips_specific (FILE * file) Link Here
13432
		  _("Ndx"), _("Name"));
13496
		  _("Ndx"), _("Name"));
13433
13497
13434
	  sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
13498
	  sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1;
13499
13435
	  for (i = gotsym; i < symtabno; i++)
13500
	  for (i = gotsym; i < symtabno; i++)
13436
	    {
13501
	    {
13437
	      Elf_Internal_Sym * psym;
13438
13439
	      psym = dynamic_symbols + i;
13440
	      ent = print_mips_got_entry (data, pltgot, ent);
13502
	      ent = print_mips_got_entry (data, pltgot, ent);
13441
	      printf (" ");
13503
	      printf (" ");
13442
	      print_vma (psym->st_value, LONG_HEX);
13504
13443
	      printf (" %-7s %3s ",
13505
	      if (dynamic_symbols == NULL)
13444
		      get_symbol_type (ELF_ST_TYPE (psym->st_info)),
13506
		printf (_("<no dynamic symbols>"));
13445
		      get_symbol_index_type (psym->st_shndx));
13507
	      else if (i < num_dynamic_syms)
13446
	      if (VALID_DYNAMIC_NAME (psym->st_name))
13508
		{
13447
		print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
13509
		  Elf_Internal_Sym * psym = dynamic_symbols + i;
13510
13511
		  print_vma (psym->st_value, LONG_HEX);
13512
		  printf (" %-7s %3s ",
13513
			  get_symbol_type (ELF_ST_TYPE (psym->st_info)),
13514
			  get_symbol_index_type (psym->st_shndx));
13515
13516
		  if (VALID_DYNAMIC_NAME (psym->st_name))
13517
		    print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
13518
		  else
13519
		    printf (_("<corrupt: %14ld>"), psym->st_name);
13520
		}
13448
	      else
13521
	      else
13449
		printf (_("<corrupt: %14ld>"), psym->st_name);
13522
		printf (_("<symbol index %lu exceeds number of dynamic symbols>"), i);
13523
13450
	      printf ("\n");
13524
	      printf ("\n");
13451
	    }
13525
	    }
13452
	  printf ("\n");
13526
	  printf ("\n");
Lines 13505-13523 process_mips_specific (FILE * file) Link Here
13505
      sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
13579
      sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1;
13506
      for (i = 0; i < count; i++)
13580
      for (i = 0; i < count; i++)
13507
	{
13581
	{
13508
	  Elf_Internal_Sym * psym;
13582
	  unsigned long index = get_reloc_symindex (rels[i].r_info);
13509
13583
13510
	  psym = dynamic_symbols + get_reloc_symindex (rels[i].r_info);
13511
	  ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
13584
	  ent = print_mips_pltgot_entry (data, mips_pltgot, ent);
13512
	  printf (" ");
13585
	  printf (" ");
13513
	  print_vma (psym->st_value, LONG_HEX);
13586
13514
	  printf (" %-7s %3s ",
13587
	  if (index >= num_dynamic_syms)
13515
		  get_symbol_type (ELF_ST_TYPE (psym->st_info)),
13588
	    printf (_("<corrupt symbol index: %lu>"), index);
13516
		  get_symbol_index_type (psym->st_shndx));
13517
	  if (VALID_DYNAMIC_NAME (psym->st_name))
13518
	    print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
13519
	  else
13589
	  else
13520
	    printf (_("<corrupt: %14ld>"), psym->st_name);
13590
	    {
13591
	      Elf_Internal_Sym * psym = dynamic_symbols + index;
13592
13593
	      print_vma (psym->st_value, LONG_HEX);
13594
	      printf (" %-7s %3s ",
13595
		      get_symbol_type (ELF_ST_TYPE (psym->st_info)),
13596
		      get_symbol_index_type (psym->st_shndx));
13597
	      if (VALID_DYNAMIC_NAME (psym->st_name))
13598
		print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name));
13599
	      else
13600
		printf (_("<corrupt: %14ld>"), psym->st_name);
13601
	    }
13521
	  printf ("\n");
13602
	  printf ("\n");
13522
	}
13603
	}
13523
      printf ("\n");
13604
      printf ("\n");

Return to bug 17531