This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: [PATCH] memcmp() error in gas/dwarf2dbg.c
- From: Hannes Reinecke <hare at suse dot de>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Andreas Jaeger <aj at suse dot de>, binutils at sources dot redhat dot com,Martin Schwidefsky <schwidefsky at de dot ibm dot com>,Ulrich Weigand <Ulrich dot Weigand at de dot ibm dot com>
- Date: Fri, 13 Feb 2004 12:53:19 +0100
- Subject: Re: [PATCH] memcmp() error in gas/dwarf2dbg.c
- Organization: SuSE Linux AG
- References: <402CAF31.7010701@suse.de> <m3u11vdy2t.fsf@gromit.moeb> <20040213093244.GF4581@sunsite.ms.mff.cuni.cz>
Jakub Jelinek wrote:
On Fri, Feb 13, 2004 at 12:21:30PM +0100, Andreas Jaeger wrote:
--- binutils-2.14.90.0.8/gas/dwarf2dbg..c.orig 2004-02-13 11:55:05.470239719 +0100
+++ binutils-2.14.90.0.8/gas/dwarf2dbg.c 2004-02-13 11:57:23.679576129 +0100
Note this patch applies also to current CVS, Hannes noticed it with a
segmentation fault of gas due to accessing beyond the allocated memory.
[ Patch deleted ]
I very much doubt it has been tested at all.
Previously it has been doing if (...) break; in the for cycle, now
it does just tmp_len = in the for cycle and if (...) break; afterwards.
Also, calling strlen twice is a waste, relying on compiler to optimize
it out is wrong. And doing even one strlen in the cycle is too expensive.
I believe using
strncmp (filename, dirs[dir], dir_len) == 0 && dirs[dir][dir_len] == '\0'
would be much better.
Like this?
Cheers,
Hannes
--
Dr. Hannes Reinecke hare@suse.de
SuSE Linux AG S390 & zSeries
Maxfeldstraße 5 +49 911 74053 688
90409 Nürnberg http://www.suse.de
--- binutils-2.14.90.0.8/gas/dwarf2dbg.c.orig 2004-02-13 12:44:42.306841116 +0100
+++ binutils-2.14.90.0.8/gas/dwarf2dbg.c 2004-02-13 12:45:04.418980440 +0100
@@ -372,7 +372,7 @@
{
--dir_len;
for (dir = 1; dir < dirs_in_use; ++dir)
- if (memcmp (filename, dirs[dir], dir_len) == 0
+ if (strncmp (filename, dirs[dir], dir_len) == 0
&& dirs[dir][dir_len] == '\0')
break;