* PATCH: Check S-record with 0 size
@ 2014-08-28 15:25 H.J. Lu
2014-08-29 1:15 ` Alan Modra
0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2014-08-28 15:25 UTC (permalink / raw)
To: binutils
Hi,
I checked in this patch to fix S-record with 0 size reported at
http://lists.gnu.org/archive/html/bug-binutils/2014-08/msg00110.html
H.J.
---
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index bba079f..6484c91 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,7 @@
+2014-08-28 H.J. Lu <hongjiu.lu@intel.com>
+
+ * srec.c (srec_scan): Return error for 0 size.
+
2014-08-27 H.J. Lu <hongjiu.lu@intel.com>
PR ld/17306
diff --git a/bfd/srec.c b/bfd/srec.c
index f11e74a..d979bf5 100644
--- a/bfd/srec.c
+++ b/bfd/srec.c
@@ -486,7 +486,8 @@ srec_scan (bfd *abfd)
bufsize = bytes * 2;
}
- if (bfd_bread (buf, (bfd_size_type) bytes * 2, abfd) != bytes * 2)
+ if (bytes == 0
+ || bfd_bread (buf, (bfd_size_type) bytes * 2, abfd) != bytes * 2)
goto error_return;
/* Ignore the checksum byte. */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: Check S-record with 0 size
2014-08-28 15:25 PATCH: Check S-record with 0 size H.J. Lu
@ 2014-08-29 1:15 ` Alan Modra
2014-08-29 15:06 ` H.J. Lu
0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2014-08-29 1:15 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils
On Thu, Aug 28, 2014 at 08:25:34AM -0700, H.J. Lu wrote:
> Hi,
>
> I checked in this patch to fix S-record with 0 size reported at
>
> http://lists.gnu.org/archive/html/bug-binutils/2014-08/msg00110.html
We should really be testing for other invalid byte counts.
* srec.c (srec_scan): Revert last change. Report an error for
S-records with less than the miniumum byte count.
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 6484c91..3e005c9 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2014-08-29 Alan Modra <amodra@gmail.com>
+
+ * srec.c (srec_scan): Revert last change. Report an error for
+ S-records with less than the miniumum byte count.
+
2014-08-28 H.J. Lu <hongjiu.lu@intel.com>
* srec.c (srec_scan): Return error for 0 size.
diff --git a/bfd/srec.c b/bfd/srec.c
index d979bf5..42143c7 100644
--- a/bfd/srec.c
+++ b/bfd/srec.c
@@ -453,7 +453,7 @@ srec_scan (bfd *abfd)
{
file_ptr pos;
char hdr[3];
- unsigned int bytes;
+ unsigned int bytes, min_bytes;
bfd_vma address;
bfd_byte *data;
unsigned char check_sum;
@@ -476,6 +476,19 @@ srec_scan (bfd *abfd)
}
check_sum = bytes = HEX (hdr + 1);
+ min_bytes = 3;
+ if (hdr[0] == '2' || hdr[0] == '8')
+ min_bytes = 4;
+ else if (hdr[0] == '3' || hdr[0] == '7')
+ min_bytes = 5;
+ if (bytes < min_bytes)
+ {
+ (*_bfd_error_handler) (_("%B:%d: byte count %d too small\n"),
+ abfd, lineno, bytes);
+ bfd_set_error (bfd_error_bad_value);
+ goto error_return;
+ }
+
if (bytes * 2 > bufsize)
{
if (buf != NULL)
@@ -486,8 +499,7 @@ srec_scan (bfd *abfd)
bufsize = bytes * 2;
}
- if (bytes == 0
- || bfd_bread (buf, (bfd_size_type) bytes * 2, abfd) != bytes * 2)
+ if (bfd_bread (buf, (bfd_size_type) bytes * 2, abfd) != bytes * 2)
goto error_return;
/* Ignore the checksum byte. */
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: Check S-record with 0 size
2014-08-29 1:15 ` Alan Modra
@ 2014-08-29 15:06 ` H.J. Lu
2014-08-30 1:42 ` Alan Modra
0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2014-08-29 15:06 UTC (permalink / raw)
To: Binutils
On Thu, Aug 28, 2014 at 6:15 PM, Alan Modra <amodra@gmail.com> wrote:
> On Thu, Aug 28, 2014 at 08:25:34AM -0700, H.J. Lu wrote:
>> Hi,
>>
>> I checked in this patch to fix S-record with 0 size reported at
>>
>> http://lists.gnu.org/archive/html/bug-binutils/2014-08/msg00110.html
>
> We should really be testing for other invalid byte counts.
>
> * srec.c (srec_scan): Revert last change. Report an error for
> S-records with less than the miniumum byte count.
>
I don't think it is desirable. For the given testcase, now we got
[hjl@gnu-6 binutils]$ ./strings /tmp/ohcrap.txt
BFD: /tmp/ohcrap.txt:1: byte count 0 too small
S700
[hjl@gnu-6 binutils]$
We should generate
[hjl@gnu-6 binutils]$ ./strings /tmp/ohcrap.txt
S700
[hjl@gnu-6 binutils]$
--
H.J.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH: Check S-record with 0 size
2014-08-29 15:06 ` H.J. Lu
@ 2014-08-30 1:42 ` Alan Modra
0 siblings, 0 replies; 4+ messages in thread
From: Alan Modra @ 2014-08-30 1:42 UTC (permalink / raw)
To: H.J. Lu; +Cc: Binutils
On Fri, Aug 29, 2014 at 08:06:28AM -0700, H.J. Lu wrote:
> On Thu, Aug 28, 2014 at 6:15 PM, Alan Modra <amodra@gmail.com> wrote:
> > On Thu, Aug 28, 2014 at 08:25:34AM -0700, H.J. Lu wrote:
> >> Hi,
> >>
> >> I checked in this patch to fix S-record with 0 size reported at
> >>
> >> http://lists.gnu.org/archive/html/bug-binutils/2014-08/msg00110.html
> >
> > We should really be testing for other invalid byte counts.
> >
> > * srec.c (srec_scan): Revert last change. Report an error for
> > S-records with less than the miniumum byte count.
> >
>
> I don't think it is desirable. For the given testcase, now we got
>
> [hjl@gnu-6 binutils]$ ./strings /tmp/ohcrap.txt
> BFD: /tmp/ohcrap.txt:1: byte count 0 too small
>
> S700
The thing is that srec_scan ought to provide this information in the
bulk of the file. For example, if someone has been editing an
S-record file and gets something wrong, then it is good to know which
line.
On the other hand, srec_object_p shouldn't really be returning any
errors other than bfd_error_wrong_format, or fatal errors like
bfd_error_no_memory. The difficulty is that srec_object_p does more
than just decide whether the bfd is an srec file; It parses the
entire file. In effect, any error results in "this isn't an srec
file". So if we don't report S-record errors in srec_scan, we won't
have an opportunity to report them later.
I thought about fixing this by extracting "case 'S'" from srec_scan
into a separate function, untangling all the error reporting, then
using the new function in srec_object_p to verify the first line was a
valid S-record. ie. in place of
if (b[0] != 'S' || !ISHEX (b[1]) || !ISHEX (b[2]) || !ISHEX (b[3]))
{
bfd_set_error (bfd_error_wrong_format);
return NULL;
}
That seemed like too much work for little benefit.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-08-30 1:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-28 15:25 PATCH: Check S-record with 0 size H.J. Lu
2014-08-29 1:15 ` Alan Modra
2014-08-29 15:06 ` H.J. Lu
2014-08-30 1:42 ` Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).