* elf64-ppc.c (ppc_add_stub): Replace strcpy/strncpy with memcpy.

* elf32-hppa.c (hppa_add_stub): Likewise.
	* elflink.c (_bfd_elf_link_record_dynamic_symbol): Likewise.
	* elflink.h (elf_add_default_symbol): Fix comment typo.
	(elf_add_default_symbol): Replace strcpy and strncpy with memcpy.
	(elf_link_add_object_symbols): Likewise.
	(elf_link_assign_sym_version): Likewise.
	* hash.c (bfd_hash_lookup): Likewise.
	* linker.c (_bfd_generic_link_add_one_symbol): Likewise.
	* section.c (bfd_get_unique_section_name): Likewise.
	* syms.c (_bfd_stab_section_find_nearest_line): Likewise.
	* elf.c (_bfd_elf_make_section_from_phdr): Likewise.
	(assign_section_numbers): Likewise.
	(_bfd_elfcore_make_pseudosection): Likewise.
	(elfcore_grok_lwpstatus): Likewise.
	(elfcore_grok_win32pstatus): Likewise.
	(elfcore_write_note): Constify input params.  Use PTR instead of
	void *.  Include terminating NUL in namesz.  Correct padding.
	Support NULL "name" param.  Use memcpy instead of strcpy.
	(elfcore_write_prpsinfo): Constify input params.
	(elfcore_write_prstatus): Likewise.  Use PTR instead of void *.
	(elfcore_write_lwpstatus): Likewise.
	(elfcore_write_pstatus): Likewise.
	(elfcore_write_prfpreg): Likewise.
	(elfcore_write_prxfpreg): Likewise.
	* elf-bfd.h (elfcore_write_note): Update declaration.
	(elfcore_write_prpsinfo): Likewise.
	(elfcore_write_prstatus): Likewise.
	(elfcore_write_pstatus): Likewise.
	(elfcore_write_prfpreg): Likewise.
	(elfcore_write_prxfpreg): Likewise.
	(elfcore_write_lwpstatus): Likewise.
This commit is contained in:
Alan Modra 2002-06-25 09:40:45 +00:00
parent b0ac09d2fb
commit d4c88bbbc9
11 changed files with 170 additions and 86 deletions

View file

@ -1,3 +1,38 @@
2002-06-25 Alan Modra <amodra@bigpond.net.au>
* elf64-ppc.c (ppc_add_stub): Replace strcpy/strncpy with memcpy.
* elf32-hppa.c (hppa_add_stub): Likewise.
* elflink.c (_bfd_elf_link_record_dynamic_symbol): Likewise.
* elflink.h (elf_add_default_symbol): Fix comment typo.
(elf_add_default_symbol): Replace strcpy and strncpy with memcpy.
(elf_link_add_object_symbols): Likewise.
(elf_link_assign_sym_version): Likewise.
* hash.c (bfd_hash_lookup): Likewise.
* linker.c (_bfd_generic_link_add_one_symbol): Likewise.
* section.c (bfd_get_unique_section_name): Likewise.
* syms.c (_bfd_stab_section_find_nearest_line): Likewise.
* elf.c (_bfd_elf_make_section_from_phdr): Likewise.
(assign_section_numbers): Likewise.
(_bfd_elfcore_make_pseudosection): Likewise.
(elfcore_grok_lwpstatus): Likewise.
(elfcore_grok_win32pstatus): Likewise.
(elfcore_write_note): Constify input params. Use PTR instead of
void *. Include terminating NUL in namesz. Correct padding.
Support NULL "name" param. Use memcpy instead of strcpy.
(elfcore_write_prpsinfo): Constify input params.
(elfcore_write_prstatus): Likewise. Use PTR instead of void *.
(elfcore_write_lwpstatus): Likewise.
(elfcore_write_pstatus): Likewise.
(elfcore_write_prfpreg): Likewise.
(elfcore_write_prxfpreg): Likewise.
* elf-bfd.h (elfcore_write_note): Update declaration.
(elfcore_write_prpsinfo): Likewise.
(elfcore_write_prstatus): Likewise.
(elfcore_write_pstatus): Likewise.
(elfcore_write_prfpreg): Likewise.
(elfcore_write_prxfpreg): Likewise.
(elfcore_write_lwpstatus): Likewise.
2002-06-25 Jason Eckhardt <jle@rice.edu> 2002-06-25 Jason Eckhardt <jle@rice.edu>
* ecoff.c (ecoff_set_symbol_info): Set BSF_FUNCTION for * ecoff.c (ecoff_set_symbol_info): Set BSF_FUNCTION for

View file

@ -1593,19 +1593,19 @@ extern boolean _bfd_elf64_reloc_symbol_deleted_p
/* Exported interface for writing elf corefile notes. */ /* Exported interface for writing elf corefile notes. */
extern char *elfcore_write_note extern char *elfcore_write_note
PARAMS ((bfd *, char *, int *, char *, int, void *, int)); PARAMS ((bfd *, char *, int *, const char *, int, const PTR, int));
extern char *elfcore_write_prpsinfo extern char *elfcore_write_prpsinfo
PARAMS ((bfd *, char *, int *, char *, char *)); PARAMS ((bfd *, char *, int *, const char *, const char *));
extern char *elfcore_write_prstatus extern char *elfcore_write_prstatus
PARAMS ((bfd *, char *, int *, long, int, void *)); PARAMS ((bfd *, char *, int *, long, int, const PTR));
extern char * elfcore_write_pstatus extern char * elfcore_write_pstatus
PARAMS ((bfd *, char *, int *, long, int, void *)); PARAMS ((bfd *, char *, int *, long, int, const PTR));
extern char *elfcore_write_prfpreg extern char *elfcore_write_prfpreg
PARAMS ((bfd *, char *, int *, void *, int)); PARAMS ((bfd *, char *, int *, const PTR, int));
extern char *elfcore_write_prxfpreg extern char *elfcore_write_prxfpreg
PARAMS ((bfd *, char *, int *, void *, int)); PARAMS ((bfd *, char *, int *, const PTR, int));
extern char *elfcore_write_lwpstatus extern char *elfcore_write_lwpstatus
PARAMS ((bfd*, char*, int*, long, int, void*)); PARAMS ((bfd *, char *, int *, long, int, const PTR));
/* SH ELF specific routine. */ /* SH ELF specific routine. */

View file

@ -2071,16 +2071,18 @@ _bfd_elf_make_section_from_phdr (abfd, hdr, index, typename)
asection *newsect; asection *newsect;
char *name; char *name;
char namebuf[64]; char namebuf[64];
size_t len;
int split; int split;
split = ((hdr->p_memsz > 0) split = ((hdr->p_memsz > 0)
&& (hdr->p_filesz > 0) && (hdr->p_filesz > 0)
&& (hdr->p_memsz > hdr->p_filesz)); && (hdr->p_memsz > hdr->p_filesz));
sprintf (namebuf, "%s%d%s", typename, index, split ? "a" : ""); sprintf (namebuf, "%s%d%s", typename, index, split ? "a" : "");
name = bfd_alloc (abfd, (bfd_size_type) strlen (namebuf) + 1); len = strlen (namebuf) + 1;
name = bfd_alloc (abfd, (bfd_size_type) len);
if (!name) if (!name)
return false; return false;
strcpy (name, namebuf); memcpy (name, namebuf, len);
newsect = bfd_make_section (abfd, name); newsect = bfd_make_section (abfd, name);
if (newsect == NULL) if (newsect == NULL)
return false; return false;
@ -2108,10 +2110,11 @@ _bfd_elf_make_section_from_phdr (abfd, hdr, index, typename)
if (split) if (split)
{ {
sprintf (namebuf, "%s%db", typename, index); sprintf (namebuf, "%s%db", typename, index);
name = bfd_alloc (abfd, (bfd_size_type) strlen (namebuf) + 1); len = strlen (namebuf) + 1;
name = bfd_alloc (abfd, (bfd_size_type) len);
if (!name) if (!name)
return false; return false;
strcpy (name, namebuf); memcpy (name, namebuf, len);
newsect = bfd_make_section (abfd, name); newsect = bfd_make_section (abfd, name);
if (newsect == NULL) if (newsect == NULL)
return false; return false;
@ -2666,10 +2669,10 @@ assign_section_numbers (abfd)
char *alc; char *alc;
len = strlen (sec->name); len = strlen (sec->name);
alc = (char *) bfd_malloc ((bfd_size_type) len - 2); alc = (char *) bfd_malloc ((bfd_size_type) (len - 2));
if (alc == NULL) if (alc == NULL)
return false; return false;
strncpy (alc, sec->name, len - 3); memcpy (alc, sec->name, len - 3);
alc[len - 3] = '\0'; alc[len - 3] = '\0';
s = bfd_get_section_by_name (abfd, alc); s = bfd_get_section_by_name (abfd, alc);
free (alc); free (alc);
@ -6189,15 +6192,17 @@ _bfd_elfcore_make_pseudosection (abfd, name, size, filepos)
{ {
char buf[100]; char buf[100];
char *threaded_name; char *threaded_name;
size_t len;
asection *sect; asection *sect;
/* Build the section name. */ /* Build the section name. */
sprintf (buf, "%s/%d", name, elfcore_make_pid (abfd)); sprintf (buf, "%s/%d", name, elfcore_make_pid (abfd));
threaded_name = bfd_alloc (abfd, (bfd_size_type) strlen (buf) + 1); len = strlen (buf) + 1;
threaded_name = bfd_alloc (abfd, (bfd_size_type) len);
if (threaded_name == NULL) if (threaded_name == NULL)
return false; return false;
strcpy (threaded_name, buf); memcpy (threaded_name, buf, len);
sect = bfd_make_section (abfd, threaded_name); sect = bfd_make_section (abfd, threaded_name);
if (sect == NULL) if (sect == NULL)
@ -6482,6 +6487,7 @@ elfcore_grok_lwpstatus (abfd, note)
lwpstatus_t lwpstat; lwpstatus_t lwpstat;
char buf[100]; char buf[100];
char *name; char *name;
size_t len;
asection *sect; asection *sect;
if (note->descsz != sizeof (lwpstat) if (note->descsz != sizeof (lwpstat)
@ -6499,10 +6505,11 @@ elfcore_grok_lwpstatus (abfd, note)
/* Make a ".reg/999" section. */ /* Make a ".reg/999" section. */
sprintf (buf, ".reg/%d", elfcore_make_pid (abfd)); sprintf (buf, ".reg/%d", elfcore_make_pid (abfd));
name = bfd_alloc (abfd, (bfd_size_type) strlen (buf) + 1); len = strlen (buf) + 1;
name = bfd_alloc (abfd, (bfd_size_type) len);
if (name == NULL) if (name == NULL)
return false; return false;
strcpy (name, buf); memcpy (name, buf, len);
sect = bfd_make_section (abfd, name); sect = bfd_make_section (abfd, name);
if (sect == NULL) if (sect == NULL)
@ -6528,10 +6535,11 @@ elfcore_grok_lwpstatus (abfd, note)
/* Make a ".reg2/999" section */ /* Make a ".reg2/999" section */
sprintf (buf, ".reg2/%d", elfcore_make_pid (abfd)); sprintf (buf, ".reg2/%d", elfcore_make_pid (abfd));
name = bfd_alloc (abfd, (bfd_size_type) strlen (buf) + 1); len = strlen (buf) + 1;
name = bfd_alloc (abfd, (bfd_size_type) len);
if (name == NULL) if (name == NULL)
return false; return false;
strcpy (name, buf); memcpy (name, buf, len);
sect = bfd_make_section (abfd, name); sect = bfd_make_section (abfd, name);
if (sect == NULL) if (sect == NULL)
@ -6563,6 +6571,7 @@ elfcore_grok_win32pstatus (abfd, note)
{ {
char buf[30]; char buf[30];
char *name; char *name;
size_t len;
asection *sect; asection *sect;
win32_pstatus_t pstatus; win32_pstatus_t pstatus;
@ -6583,11 +6592,12 @@ elfcore_grok_win32pstatus (abfd, note)
/* Make a ".reg/999" section. */ /* Make a ".reg/999" section. */
sprintf (buf, ".reg/%d", pstatus.data.thread_info.tid); sprintf (buf, ".reg/%d", pstatus.data.thread_info.tid);
name = bfd_alloc (abfd, (bfd_size_type) strlen (buf) + 1); len = strlen (buf) + 1;
name = bfd_alloc (abfd, (bfd_size_type) len);
if (name == NULL) if (name == NULL)
return false; return false;
strcpy (name, buf); memcpy (name, buf, len);
sect = bfd_make_section (abfd, name); sect = bfd_make_section (abfd, name);
if (sect == NULL) if (sect == NULL)
@ -6609,11 +6619,12 @@ elfcore_grok_win32pstatus (abfd, note)
/* Make a ".module/xxxxxxxx" section. */ /* Make a ".module/xxxxxxxx" section. */
sprintf (buf, ".module/%08x", pstatus.data.module_info.base_address); sprintf (buf, ".module/%08x", pstatus.data.module_info.base_address);
name = bfd_alloc (abfd, (bfd_size_type) strlen (buf) + 1); len = strlen (buf) + 1;
name = bfd_alloc (abfd, (bfd_size_type) len);
if (name == NULL) if (name == NULL)
return false; return false;
strcpy (name, buf); memcpy (name, buf, len);
sect = bfd_make_section (abfd, name); sect = bfd_make_section (abfd, name);
@ -6815,16 +6826,30 @@ elfcore_write_note (abfd, buf, bufsiz, name, type, input, size)
bfd *abfd; bfd *abfd;
char *buf; char *buf;
int *bufsiz; int *bufsiz;
char *name; const char *name;
int type; int type;
void *input; const PTR input;
int size; int size;
{ {
Elf_External_Note *xnp; Elf_External_Note *xnp;
int namesz = strlen (name); size_t namesz;
int newspace = BFD_ALIGN (sizeof (Elf_External_Note) + size + namesz - 1, 4); size_t pad;
size_t newspace;
char *p, *dest; char *p, *dest;
namesz = 0;
pad = 0;
if (name != NULL)
{
struct elf_backend_data *bed;
namesz = strlen (name) + 1;
bed = get_elf_backend_data (abfd);
pad = -namesz & (bed->s->file_align - 1);
}
newspace = sizeof (Elf_External_Note) - 1 + namesz + pad + size;
p = realloc (buf, *bufsiz + newspace); p = realloc (buf, *bufsiz + newspace);
dest = p + *bufsiz; dest = p + *bufsiz;
*bufsiz += newspace; *bufsiz += newspace;
@ -6832,8 +6857,18 @@ elfcore_write_note (abfd, buf, bufsiz, name, type, input, size)
H_PUT_32 (abfd, namesz, xnp->namesz); H_PUT_32 (abfd, namesz, xnp->namesz);
H_PUT_32 (abfd, size, xnp->descsz); H_PUT_32 (abfd, size, xnp->descsz);
H_PUT_32 (abfd, type, xnp->type); H_PUT_32 (abfd, type, xnp->type);
strcpy (xnp->name, name); dest = xnp->name;
memcpy (xnp->name + BFD_ALIGN (namesz, 4), input, size); if (name != NULL)
{
memcpy (dest, name, namesz);
dest += namesz;
while (pad != 0)
{
*dest++ = '\0';
--pad;
}
}
memcpy (dest, input, size);
return p; return p;
} }
@ -6843,8 +6878,8 @@ elfcore_write_prpsinfo (abfd, buf, bufsiz, fname, psargs)
bfd *abfd; bfd *abfd;
char *buf; char *buf;
int *bufsiz; int *bufsiz;
char *fname; const char *fname;
char *psargs; const char *psargs;
{ {
int note_type; int note_type;
char *note_name = "CORE"; char *note_name = "CORE";
@ -6873,7 +6908,7 @@ elfcore_write_prstatus (abfd, buf, bufsiz, pid, cursig, gregs)
int *bufsiz; int *bufsiz;
long pid; long pid;
int cursig; int cursig;
void *gregs; const PTR gregs;
{ {
prstatus_t prstat; prstatus_t prstat;
char *note_name = "CORE"; char *note_name = "CORE";
@ -6895,7 +6930,7 @@ elfcore_write_lwpstatus (abfd, buf, bufsiz, pid, cursig, gregs)
int *bufsiz; int *bufsiz;
long pid; long pid;
int cursig; int cursig;
void *gregs; const PTR gregs;
{ {
lwpstatus_t lwpstat; lwpstatus_t lwpstat;
char *note_name = "CORE"; char *note_name = "CORE";
@ -6927,7 +6962,7 @@ elfcore_write_pstatus (abfd, buf, bufsiz, pid, cursig, gregs)
int *bufsiz; int *bufsiz;
long pid; long pid;
int cursig; int cursig;
void *gregs; const PTR gregs;
{ {
pstatus_t pstat; pstatus_t pstat;
char *note_name = "CORE"; char *note_name = "CORE";
@ -6945,7 +6980,7 @@ elfcore_write_prfpreg (abfd, buf, bufsiz, fpregs, size)
bfd *abfd; bfd *abfd;
char *buf; char *buf;
int *bufsiz; int *bufsiz;
void *fpregs; const PTR fpregs;
int size; int size;
{ {
char *note_name = "CORE"; char *note_name = "CORE";
@ -6958,7 +6993,7 @@ elfcore_write_prxfpreg (abfd, buf, bufsiz, xfpregs, size)
bfd *abfd; bfd *abfd;
char *buf; char *buf;
int *bufsiz; int *bufsiz;
void *xfpregs; const PTR xfpregs;
int size; int size;
{ {
char *note_name = "LINUX"; char *note_name = "LINUX";

View file

@ -643,16 +643,18 @@ hppa_add_stub (stub_name, section, htab)
stub_sec = htab->stub_group[link_sec->id].stub_sec; stub_sec = htab->stub_group[link_sec->id].stub_sec;
if (stub_sec == NULL) if (stub_sec == NULL)
{ {
size_t namelen;
bfd_size_type len; bfd_size_type len;
char *s_name; char *s_name;
len = strlen (link_sec->name) + sizeof (STUB_SUFFIX); namelen = strlen (link_sec->name);
len = namelen + sizeof (STUB_SUFFIX);
s_name = bfd_alloc (htab->stub_bfd, len); s_name = bfd_alloc (htab->stub_bfd, len);
if (s_name == NULL) if (s_name == NULL)
return NULL; return NULL;
strcpy (s_name, link_sec->name); memcpy (s_name, link_sec->name, namelen);
strcpy (s_name + len - sizeof (STUB_SUFFIX), STUB_SUFFIX); memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
stub_sec = (*htab->add_stub_section) (s_name, link_sec); stub_sec = (*htab->add_stub_section) (s_name, link_sec);
if (stub_sec == NULL) if (stub_sec == NULL)
return NULL; return NULL;

View file

@ -2413,16 +2413,18 @@ ppc_add_stub (stub_name, section, htab)
stub_sec = htab->stub_group[link_sec->id].stub_sec; stub_sec = htab->stub_group[link_sec->id].stub_sec;
if (stub_sec == NULL) if (stub_sec == NULL)
{ {
size_t namelen;
bfd_size_type len; bfd_size_type len;
char *s_name; char *s_name;
len = strlen (link_sec->name) + sizeof (STUB_SUFFIX); namelen = strlen (link_sec->name);
len = namelen + sizeof (STUB_SUFFIX);
s_name = bfd_alloc (htab->stub_bfd, len); s_name = bfd_alloc (htab->stub_bfd, len);
if (s_name == NULL) if (s_name == NULL)
return NULL; return NULL;
strcpy (s_name, link_sec->name); memcpy (s_name, link_sec->name, namelen);
strcpy (s_name + len - sizeof (STUB_SUFFIX), STUB_SUFFIX); memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
stub_sec = (*htab->add_stub_section) (s_name, link_sec); stub_sec = (*htab->add_stub_section) (s_name, link_sec);
if (stub_sec == NULL) if (stub_sec == NULL)
return NULL; return NULL;

View file

@ -278,11 +278,13 @@ _bfd_elf_link_record_dynamic_symbol (info, h)
} }
else else
{ {
alc = bfd_malloc ((bfd_size_type) (p - name + 1)); size_t len = p - name + 1;
alc = bfd_malloc ((bfd_size_type) len);
if (alc == NULL) if (alc == NULL)
return false; return false;
strncpy (alc, name, (size_t) (p - name)); memcpy (alc, name, len - 1);
alc[p - name] = '\0'; alc[len - 1] = '\0';
name = alc; name = alc;
copy = true; copy = true;
} }

View file

@ -960,6 +960,7 @@ elf_add_default_symbol (abfd, info, h, name, sym, sec, value,
boolean collect; boolean collect;
boolean dynamic; boolean dynamic;
char *p; char *p;
size_t len, shortlen;
/* If this symbol has a version, and it is the default version, we /* If this symbol has a version, and it is the default version, we
create an indirect symbol from the default name to the fully create an indirect symbol from the default name to the fully
@ -972,7 +973,7 @@ elf_add_default_symbol (abfd, info, h, name, sym, sec, value,
if (override) if (override)
{ {
/* We are overridden by an old defition. We need to check if we /* We are overridden by an old defition. We need to check if we
need to crreate the indirect symbol from the default name. */ need to create the indirect symbol from the default name. */
hi = elf_link_hash_lookup (elf_hash_table (info), name, true, hi = elf_link_hash_lookup (elf_hash_table (info), name, true,
false, false); false, false);
BFD_ASSERT (hi != NULL); BFD_ASSERT (hi != NULL);
@ -991,12 +992,12 @@ elf_add_default_symbol (abfd, info, h, name, sym, sec, value,
collect = bed->collect; collect = bed->collect;
dynamic = (abfd->flags & DYNAMIC) != 0; dynamic = (abfd->flags & DYNAMIC) != 0;
shortname = bfd_hash_allocate (&info->hash->table, shortlen = p - name;
(size_t) (p - name + 1)); shortname = bfd_hash_allocate (&info->hash->table, shortlen + 1);
if (shortname == NULL) if (shortname == NULL)
return false; return false;
strncpy (shortname, name, (size_t) (p - name)); memcpy (shortname, name, shortlen);
shortname [p - name] = '\0'; shortname[shortlen] = '\0';
/* We are going to create a new symbol. Merge it with any existing /* We are going to create a new symbol. Merge it with any existing
symbol with this name. For the purposes of the merge, act as symbol with this name. For the purposes of the merge, act as
@ -1101,11 +1102,12 @@ elf_add_default_symbol (abfd, info, h, name, sym, sec, value,
/* We also need to define an indirection from the nondefault version /* We also need to define an indirection from the nondefault version
of the symbol. */ of the symbol. */
shortname = bfd_hash_allocate (&info->hash->table, strlen (name)); len = strlen (name);
shortname = bfd_hash_allocate (&info->hash->table, len);
if (shortname == NULL) if (shortname == NULL)
return false; return false;
strncpy (shortname, name, (size_t) (p - name)); memcpy (shortname, name, shortlen);
strcpy (shortname + (p - name), p + 1); memcpy (shortname + shortlen, p + 1, len - shortlen);
/* Once again, merge with any existing symbol. */ /* Once again, merge with any existing symbol. */
type_change_ok = false; type_change_ok = false;
@ -1493,10 +1495,11 @@ elf_link_add_object_symbols (abfd, info)
fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv); fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
if (n == NULL || fnm == NULL) if (n == NULL || fnm == NULL)
goto error_return; goto error_return;
anm = bfd_alloc (abfd, (bfd_size_type) strlen (fnm) + 1); amt = strlen (fnm) + 1;
anm = bfd_alloc (abfd, amt);
if (anm == NULL) if (anm == NULL)
goto error_return; goto error_return;
strcpy (anm, fnm); memcpy (anm, fnm, (size_t) amt);
n->name = anm; n->name = anm;
n->by = abfd; n->by = abfd;
n->next = NULL; n->next = NULL;
@ -1524,10 +1527,11 @@ elf_link_add_object_symbols (abfd, info)
fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv); fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
if (n == NULL || fnm == NULL) if (n == NULL || fnm == NULL)
goto error_return; goto error_return;
anm = bfd_alloc (abfd, (bfd_size_type) strlen (fnm) + 1); amt = strlen (fnm) + 1;
anm = bfd_alloc (abfd, amt);
if (anm == NULL) if (anm == NULL)
goto error_return; goto error_return;
strcpy (anm, fnm); memcpy (anm, fnm, (size_t) amt);
n->name = anm; n->name = anm;
n->by = abfd; n->by = abfd;
n->next = NULL; n->next = NULL;
@ -1551,10 +1555,11 @@ elf_link_add_object_symbols (abfd, info)
fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv); fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
if (n == NULL || fnm == NULL) if (n == NULL || fnm == NULL)
goto error_return; goto error_return;
anm = bfd_alloc (abfd, (bfd_size_type) strlen (fnm) + 1); amt = strlen (fnm) + 1;
anm = bfd_alloc (abfd, amt);
if (anm == NULL) if (anm == NULL)
goto error_return; goto error_return;
strcpy (anm, fnm); memcpy (anm, fnm, (size_t) amt);
n->name = anm; n->name = anm;
n->by = abfd; n->by = abfd;
n->next = NULL; n->next = NULL;
@ -1798,8 +1803,7 @@ elf_link_add_object_symbols (abfd, info)
|| (vernum > 1 && ! bfd_is_abs_section (sec))) || (vernum > 1 && ! bfd_is_abs_section (sec)))
{ {
const char *verstr; const char *verstr;
unsigned int namelen; size_t namelen, verlen, newlen;
bfd_size_type newlen;
char *newname, *p; char *newname, *p;
if (sym.st_shndx != SHN_UNDEF) if (sym.st_shndx != SHN_UNDEF)
@ -1856,14 +1860,16 @@ elf_link_add_object_symbols (abfd, info)
} }
namelen = strlen (name); namelen = strlen (name);
newlen = namelen + strlen (verstr) + 2; verlen = strlen (verstr);
if ((iver.vs_vers & VERSYM_HIDDEN) == 0) newlen = namelen + verlen + 2;
if ((iver.vs_vers & VERSYM_HIDDEN) == 0
&& sym.st_shndx != SHN_UNDEF)
++newlen; ++newlen;
newname = (char *) bfd_alloc (abfd, newlen); newname = (char *) bfd_alloc (abfd, (bfd_size_type) newlen);
if (newname == NULL) if (newname == NULL)
goto error_return; goto error_return;
strcpy (newname, name); memcpy (newname, name, namelen);
p = newname + namelen; p = newname + namelen;
*p++ = ELF_VER_CHR; *p++ = ELF_VER_CHR;
/* If this is a defined non-hidden version symbol, /* If this is a defined non-hidden version symbol,
@ -1872,7 +1878,7 @@ elf_link_add_object_symbols (abfd, info)
if ((iver.vs_vers & VERSYM_HIDDEN) == 0 if ((iver.vs_vers & VERSYM_HIDDEN) == 0
&& sym.st_shndx != SHN_UNDEF) && sym.st_shndx != SHN_UNDEF)
*p++ = ELF_VER_CHR; *p++ = ELF_VER_CHR;
strcpy (p, verstr); memcpy (p, verstr, verlen + 1);
name = newname; name = newname;
} }
@ -4339,7 +4345,7 @@ elf_link_assign_sym_version (h, data)
alc = bfd_malloc ((bfd_size_type) len); alc = bfd_malloc ((bfd_size_type) len);
if (alc == NULL) if (alc == NULL)
return false; return false;
strncpy (alc, h->root.root.string, len - 1); memcpy (alc, h->root.root.string, len - 1);
alc[len - 1] = '\0'; alc[len - 1] = '\0';
if (alc[len - 2] == ELF_VER_CHR) if (alc[len - 2] == ELF_VER_CHR)
alc[len - 2] = '\0'; alc[len - 2] = '\0';

View file

@ -1,5 +1,5 @@
/* hash.c -- hash table routines for BFD /* hash.c -- hash table routines for BFD
Copyright 1993, 1994, 1995, 1997, 1999, 2001 Copyright 1993, 1994, 1995, 1997, 1999, 2001, 2002
Free Software Foundation, Inc. Free Software Foundation, Inc.
Written by Steve Chamberlain <sac@cygnus.com> Written by Steve Chamberlain <sac@cygnus.com>
@ -407,7 +407,7 @@ bfd_hash_lookup (table, string, create, copy)
bfd_set_error (bfd_error_no_memory); bfd_set_error (bfd_error_no_memory);
return (struct bfd_hash_entry *) NULL; return (struct bfd_hash_entry *) NULL;
} }
strcpy (new, string); memcpy (new, string, len + 1);
string = new; string = new;
} }
hashp->string = string; hashp->string = string;

View file

@ -1974,12 +1974,12 @@ _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section, value,
else else
{ {
char *w; char *w;
size_t len = strlen (string) + 1;
w = bfd_hash_allocate (&info->hash->table, w = bfd_hash_allocate (&info->hash->table, len);
strlen (string) + 1);
if (w == NULL) if (w == NULL)
return false; return false;
strcpy (w, string); memcpy (w, string, len);
sub->u.i.warning = w; sub->u.i.warning = w;
} }

View file

@ -798,7 +798,7 @@ bfd_get_unique_section_name (abfd, templat, count)
sname = bfd_malloc ((bfd_size_type) len + 8); sname = bfd_malloc ((bfd_size_type) len + 8);
if (sname == NULL) if (sname == NULL)
return NULL; return NULL;
strcpy (sname, templat); memcpy (sname, templat, len);
num = 1; num = 1;
if (count != NULL) if (count != NULL)
num = *count; num = *count;

View file

@ -1313,14 +1313,16 @@ _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, pfound,
|| strncmp (info->filename, directory_name, dirlen) != 0 || strncmp (info->filename, directory_name, dirlen) != 0
|| strcmp (info->filename + dirlen, file_name) != 0) || strcmp (info->filename + dirlen, file_name) != 0)
{ {
size_t len;
if (info->filename != NULL) if (info->filename != NULL)
free (info->filename); free (info->filename);
info->filename = (char *) bfd_malloc ((bfd_size_type) dirlen len = strlen (file_name) + 1;
+ strlen (file_name) + 1); info->filename = (char *) bfd_malloc ((bfd_size_type) dirlen + len);
if (info->filename == NULL) if (info->filename == NULL)
return false; return false;
strcpy (info->filename, directory_name); memcpy (info->filename, directory_name, dirlen);
strcpy (info->filename + dirlen, file_name); memcpy (info->filename + dirlen, file_name, len);
} }
*pfilename = info->filename; *pfilename = info->filename;