Skip to content

Commit

Permalink
3451 archive libraries with no symbols shouldn't require a string table
Browse files Browse the repository at this point in the history
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Jason King <jason.brian.king@gmail.com>
Approved by: Garrett D'Amore <garrett@damore.org>
  • Loading branch information
richlowe committed Jan 10, 2013
1 parent 8a8ef76 commit 87c7234
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
33 changes: 20 additions & 13 deletions usr/src/cmd/sgs/libelf/common/getarsym.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -105,36 +105,43 @@ arsym(Byte *off, size_t sz, size_t *e, int is64)
if (is64) { if (is64) {
if (sz < 8 || (sz - 8) / 8 < (n = get8(off))) { if (sz < 8 || (sz - 8) / 8 < (n = get8(off))) {
_elf_seterr(EFMT_ARSYMSZ, 0); _elf_seterr(EFMT_ARSYMSZ, 0);
return (0); return (NULL);
} }
} else { } else {
if (sz < 4 || (sz - 4) / 4 < (n = get4(off))) { if (sz < 4 || (sz - 4) / 4 < (n = get4(off))) {
_elf_seterr(EFMT_ARSYMSZ, 0); _elf_seterr(EFMT_ARSYMSZ, 0);
return (0); return (NULL);
} }
} }
off += eltsize; off += eltsize;
endoff = off + n * eltsize; endoff = off + n * eltsize;


/* /*
* string table must be present, null terminated * If there are symbols in the symbol table, a
* string table must be present and NULL terminated.
*
* The format dictates that the string table must always be
* present, however in the case of an archive containing no
* symbols GNU ar will not create one. We are permissive for
* the sake of compatibility.
*/ */

if ((n > 0) && (((str = (char *)endoff) >= endstr) ||
if (((str = (char *)endoff) >= endstr) || (*(endstr - 1) != '\0'))) {
(*(endstr - 1) != '\0')) {
_elf_seterr(EFMT_ARSYM, 0); _elf_seterr(EFMT_ARSYM, 0);
return (0); return (NULL);
} }


/* /*
* There is always at least one entry returned if a symtab
* exists since the table's last entry is an artificial one
* with a NULL as_name, but is included in the count.
*
* overflow can occur here, but not likely * overflow can occur here, but not likely
*/ */

*e = n + 1; *e = n + 1;
n = sizeof (Elf_Arsym) * (n + 1); if ((oas = calloc(n + 1, sizeof (Elf_Arsym))) == NULL) {
if ((oas = malloc(n)) == 0) {
_elf_seterr(EMEM_ARSYM, errno); _elf_seterr(EMEM_ARSYM, errno);
return (0); return (NULL);
} }
} }
{ {
Expand All @@ -144,7 +151,7 @@ arsym(Byte *off, size_t sz, size_t *e, int is64)
if (str >= endstr) { if (str >= endstr) {
_elf_seterr(EFMT_ARSYMSTR, 0); _elf_seterr(EFMT_ARSYMSTR, 0);
free(oas); free(oas);
return (0); return (NULL);
} }
if (is64) if (is64)
as->as_off = get8(off); as->as_off = get8(off);
Expand All @@ -158,7 +165,7 @@ arsym(Byte *off, size_t sz, size_t *e, int is64)
/* LINTED */ /* LINTED */
; ;
} }
as->as_name = 0; as->as_name = NULL;
as->as_off = 0; as->as_off = 0;
as->as_hash = ~(unsigned long)0L; as->as_hash = ~(unsigned long)0L;
} }
Expand Down
1 change: 1 addition & 0 deletions usr/src/cmd/sgs/packages/common/SUNWonld-README
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1643,3 +1643,4 @@ Bugid Risk Synopsis
3453 GNU comdat redirection does exactly the wrong thing 3453 GNU comdat redirection does exactly the wrong thing
3439 discarded sections shouldn't end up on output lists 3439 discarded sections shouldn't end up on output lists
3436 relocatable objects also need sloppy relocation 3436 relocatable objects also need sloppy relocation
3451 archive libraries with no symbols shouldn't require a string table

0 comments on commit 87c7234

Please sign in to comment.