PR 21414, null pointer deref of _bfd_elf_large_com_section sym
authorAlan Modra <amodra@gmail.com>
Sun, 23 Apr 2017 05:51:11 +0000 (15:21 +0930)
committerAlan Modra <amodra@gmail.com>
Sun, 23 Apr 2017 11:03:34 +0000 (20:33 +0930)
PR 21414
* section.c (GLOBAL_SYM_INIT): Make available in bfd.h.
* elf.c (lcomm_sym): New.
(_bfd_elf_large_com_section): Use lcomm_sym section symbol.
* bfd-in2.h: Regenerate.

bfd/ChangeLog
bfd/bfd-in2.h
bfd/elf.c
bfd/section.c

index 9b5f15d..0288046 100644 (file)
@@ -1,5 +1,13 @@
 2017-04-23  Alan Modra  <amodra@gmail.com>
 
+       PR 21414
+       * section.c (GLOBAL_SYM_INIT): Make available in bfd.h.
+       * elf.c (lcomm_sym): New.
+       (_bfd_elf_large_com_section): Use lcomm_sym section symbol.
+       * bfd-in2.h: Regenerate.
+
+2017-04-23  Alan Modra  <amodra@gmail.com>
+
        PR 21412
        * elf-bfd.h (struct elf_backend_data <get_reloc_section>): Change
        parameters and comment.
index 1d73134..17a35c0 100644 (file)
@@ -1839,6 +1839,18 @@ extern asection _bfd_std_section[4];
      { NULL }, { NULL }                                                \
     }
 
+/* We use a macro to initialize the static asymbol structures because
+   traditional C does not permit us to initialize a union member while
+   gcc warns if we don't initialize it.
+   the_bfd, name, value, attr, section [, udata]  */
+#ifdef __STDC__
+#define GLOBAL_SYM_INIT(NAME, SECTION) \
+  { 0, NAME, 0, BSF_SECTION_SYM, SECTION, { 0 }}
+#else
+#define GLOBAL_SYM_INIT(NAME, SECTION) \
+  { 0, NAME, 0, BSF_SECTION_SYM, SECTION }
+#endif
+
 void bfd_section_list_clear (bfd *);
 
 asection *bfd_get_section_by_name (bfd *abfd, const char *name);
index dd1a41f..a08e0f8 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -11244,9 +11244,11 @@ _bfd_elf_get_synthetic_symtab (bfd *abfd,
 
 /* It is only used by x86-64 so far.
    ??? This repeats *COM* id of zero.  sec->id is supposed to be unique,
-   but current usage would allow all of _bfd_std_section to be zero.  t*/
+   but current usage would allow all of _bfd_std_section to be zero.  */
+static const asymbol lcomm_sym
+  = GLOBAL_SYM_INIT ("LARGE_COMMON", &_bfd_elf_large_com_section);
 asection _bfd_elf_large_com_section
-  = BFD_FAKE_SECTION (_bfd_elf_large_com_section, NULL,
+  = BFD_FAKE_SECTION (_bfd_elf_large_com_section, &lcomm_sym,
                      "LARGE_COMMON", 0, SEC_IS_COMMON);
 
 void
index 4b3cf6a..28eee7f 100644 (file)
@@ -738,20 +738,20 @@ CODE_FRAGMENT
 .     { NULL }, { NULL }                                               \
 .    }
 .
+.{* We use a macro to initialize the static asymbol structures because
+.   traditional C does not permit us to initialize a union member while
+.   gcc warns if we don't initialize it.
+.   the_bfd, name, value, attr, section [, udata]  *}
+.#ifdef __STDC__
+.#define GLOBAL_SYM_INIT(NAME, SECTION) \
+.  { 0, NAME, 0, BSF_SECTION_SYM, SECTION, { 0 }}
+.#else
+.#define GLOBAL_SYM_INIT(NAME, SECTION) \
+.  { 0, NAME, 0, BSF_SECTION_SYM, SECTION }
+.#endif
+.
 */
 
-/* We use a macro to initialize the static asymbol structures because
-   traditional C does not permit us to initialize a union member while
-   gcc warns if we don't initialize it.  */
- /* the_bfd, name, value, attr, section [, udata] */
-#ifdef __STDC__
-#define GLOBAL_SYM_INIT(NAME, SECTION) \
-  { 0, NAME, 0, BSF_SECTION_SYM, SECTION, { 0 }}
-#else
-#define GLOBAL_SYM_INIT(NAME, SECTION) \
-  { 0, NAME, 0, BSF_SECTION_SYM, SECTION }
-#endif
-
 /* These symbols are global, not specific to any BFD.  Therefore, anything
    that tries to change them is broken, and should be repaired.  */