This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [patch] srec.c, avoid null ptr issues
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: msnyder at sonic dot net
- Cc: binutils at sourceware dot org
- Date: Thu, 26 Jul 2007 20:42:11 +0930
- Subject: Re: [patch] srec.c, avoid null ptr issues
- References: <15624.12.7.175.2.1185403341.squirrel@webmail.sonic.net>
On Wed, Jul 25, 2007 at 03:42:21PM -0700, msnyder@sonic.net wrote:
> If symcount is zero there's not much to do, and if csymbols
> is null we're going to dereference it (by way of alias to c).
No, because if symcount is zero, abfd->tdata.srec_data->symbols must
be NULL. When looking at this, I noticed the return value on
error was wrong. Tidied as follows.
* srec.c (srec_canonicalize_symtab): Don't alloc when symcount
is zero. Correct return value on error.
* mmo.c (mmo_canonicalize_symtab): Likewise.
* binary.c (binary_canonicalize_symtab) Correct return on error.
Index: bfd/srec.c
===================================================================
RCS file: /cvs/src/src/bfd/srec.c,v
retrieving revision 1.42
diff -u -p -r1.42 srec.c
--- bfd/srec.c 3 Jul 2007 14:26:42 -0000 1.42
+++ bfd/srec.c 26 Jul 2007 10:06:32 -0000
@@ -1125,14 +1125,14 @@ srec_canonicalize_symtab (bfd *abfd, asy
unsigned int i;
csymbols = abfd->tdata.srec_data->csymbols;
- if (csymbols == NULL)
+ if (csymbols == NULL && symcount != 0)
{
asymbol *c;
struct srec_symbol *s;
csymbols = bfd_alloc (abfd, symcount * sizeof (asymbol));
- if (csymbols == NULL && symcount != 0)
- return 0;
+ if (csymbols == NULL)
+ return -1;
abfd->tdata.srec_data->csymbols = csymbols;
for (s = abfd->tdata.srec_data->symbols, c = csymbols;
Index: bfd/binary.c
===================================================================
RCS file: /cvs/src/src/bfd/binary.c,v
retrieving revision 1.33
diff -u -p -r1.33 binary.c
--- bfd/binary.c 3 Jul 2007 14:26:39 -0000 1.33
+++ bfd/binary.c 26 Jul 2007 10:06:11 -0000
@@ -169,7 +169,7 @@ binary_canonicalize_symtab (bfd *abfd, a
syms = bfd_alloc (abfd, amt);
if (syms == NULL)
- return 0;
+ return -1;
/* Start symbol. */
syms[0].the_bfd = abfd;
Index: bfd/mmo.c
===================================================================
RCS file: /cvs/src/src/bfd/mmo.c,v
retrieving revision 1.36
diff -u -p -r1.36 mmo.c
--- bfd/mmo.c 3 Jul 2007 14:26:42 -0000 1.36
+++ bfd/mmo.c 26 Jul 2007 10:06:29 -0000
@@ -2097,7 +2097,7 @@ mmo_canonicalize_symtab (bfd *abfd, asym
unsigned int i;
csymbols = abfd->tdata.mmo_data->csymbols;
- if (csymbols == NULL)
+ if (csymbols == NULL && symcount != 0)
{
asymbol *c;
struct mmo_symbol *s;
@@ -2119,8 +2119,8 @@ mmo_canonicalize_symtab (bfd *abfd, asym
mmo_sort_mmo_symbols);
csymbols = (asymbol *) bfd_alloc (abfd, symcount * sizeof (asymbol));
- if (csymbols == NULL && symcount != 0)
- return FALSE;
+ if (csymbols == NULL)
+ return -1;
abfd->tdata.mmo_data->csymbols = csymbols;
for (msp = (struct mmo_symbol **) alocation, c = csymbols;
--
Alan Modra
Australia Development Lab, IBM