Print this page
3451 archive libraries with no symbols shouldn't require a string table

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/sgs/libelf/common/getarsym.c
          +++ new/usr/src/cmd/sgs/libelf/common/getarsym.c
↓ open down ↓ 97 lines elided ↑ open up ↑
  98   98          Byte            *endoff;
  99   99          Elf_Void        *oas;
 100  100          size_t          eltsize = is64 ? 8 : 4;
 101  101  
 102  102          {
 103  103                  register size_t n;
 104  104  
 105  105                  if (is64) {
 106  106                          if (sz < 8 || (sz - 8) / 8 < (n = get8(off))) {
 107  107                                  _elf_seterr(EFMT_ARSYMSZ, 0);
 108      -                                return (0);
      108 +                                return (NULL);
 109  109                          }
 110  110                  } else {
 111  111                          if (sz < 4 || (sz - 4) / 4 < (n = get4(off))) {
 112  112                                  _elf_seterr(EFMT_ARSYMSZ, 0);
 113      -                                return (0);
      113 +                                return (NULL);
 114  114                          }
 115  115                  }
 116  116                  off += eltsize;
 117  117                  endoff = off + n * eltsize;
 118  118  
 119  119                  /*
 120      -                 * string table must be present, null terminated
      120 +                 * If there are symbols in the symbol table, a
      121 +                 * string table must be present and NULL terminated.
      122 +                 *
      123 +                 * The format dictates that the string table must always be
      124 +                 * present, however in the case of an archive containing no
      125 +                 * symbols GNU ar will not create one.  We are permissive for
      126 +                 * the sake of compatibility.
 121  127                   */
 122      -
 123      -                if (((str = (char *)endoff) >= endstr) ||
 124      -                    (*(endstr - 1) != '\0')) {
      128 +                if ((n > 0) && (((str = (char *)endoff) >= endstr) ||
      129 +                    (*(endstr - 1) != '\0'))) {
 125  130                          _elf_seterr(EFMT_ARSYM, 0);
 126      -                        return (0);
      131 +                        return (NULL);
 127  132                  }
 128  133  
 129  134                  /*
      135 +                 * There is always at least one entry returned if a symtab
      136 +                 * exists since the table's last entry is an artificial one
      137 +                 * with a NULL as_name, but is included in the count.
      138 +                 *
 130  139                   * overflow can occur here, but not likely
 131  140                   */
 132      -
 133  141                  *e = n + 1;
 134      -                n = sizeof (Elf_Arsym) * (n + 1);
 135      -                if ((oas = malloc(n)) == 0) {
      142 +                if ((oas = calloc(n + 1, sizeof (Elf_Arsym))) == NULL) {
 136  143                          _elf_seterr(EMEM_ARSYM, errno);
 137      -                        return (0);
      144 +                        return (NULL);
 138  145                  }
 139  146          }
 140  147          {
 141  148                  register Elf_Arsym      *as = (Elf_Arsym *)oas;
 142  149  
 143  150                  while (off < endoff) {
 144  151                          if (str >= endstr) {
 145  152                                  _elf_seterr(EFMT_ARSYMSTR, 0);
 146  153                                  free(oas);
 147      -                                return (0);
      154 +                                return (NULL);
 148  155                          }
 149  156                          if (is64)
 150  157                                  as->as_off = get8(off);
 151  158                          else
 152  159                                  as->as_off = get4(off);
 153  160                          as->as_name = str;
 154  161                          as->as_hash = elf_hash(str);
 155  162                          ++as;
 156  163                          off += eltsize;
 157  164                          while (*str++ != '\0')
 158  165                                  /* LINTED */
 159  166                                  ;
 160  167                  }
 161      -                as->as_name = 0;
      168 +                as->as_name = NULL;
 162  169                  as->as_off = 0;
 163  170                  as->as_hash = ~(unsigned long)0L;
 164  171          }
 165  172          return (oas);
 166  173  }
 167  174  
 168  175  
 169  176  Elf_Arsym *
 170  177  elf_getarsym(Elf *elf, size_t *ptr)
 171  178  {
↓ open down ↓ 79 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX