aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2014-08-29 10:36:29 +0930
committerAlan Modra <amodra@gmail.com>2014-08-29 10:36:57 +0930
commitbd25671c6f202c4a5108883caa2adb24ff6f361f (patch)
tree14b6d7a1d052235fb219ba24a8d0aa4aab3b7f17
parent5a1431e66e1cebb5b4bbc6355804d8a00a4c8d74 (diff)
downloadgdb-bd25671c6f202c4a5108883caa2adb24ff6f361f.zip
gdb-bd25671c6f202c4a5108883caa2adb24ff6f361f.tar.gz
gdb-bd25671c6f202c4a5108883caa2adb24ff6f361f.tar.bz2
Report an error for S-records with less than the miniumum size
* srec.c (srec_scan): Revert last change. Report an error for S-records with less than the miniumum byte count.
-rw-r--r--bfd/ChangeLog5
-rw-r--r--bfd/srec.c18
2 files changed, 20 insertions, 3 deletions
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. */