summaryrefslogtreecommitdiff
path: root/libdw
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2018-06-08 14:04:40 +0200
committerMark Wielaard <mark@klomp.org>2018-06-10 17:02:22 +0200
commit7e30fb282d32fe3e082f66c936db4b2988c290dc (patch)
treed84c685f4088247d5d3d8c87a76f1c54f6190f29 /libdw
parentc5fdb8e5e0be9a507766a58f3c27c57703f369a9 (diff)
downloadelfutils-7e30fb282d32fe3e082f66c936db4b2988c290dc.tar.gz
readelf, libdw: Handle too many directories or files in the line table better.
The afl fuzzer found that the way we handle "too many" directories or files in the (DWARF5 style) line table badly. In the case of eu-readelf we would print an endless stream of "bad directory" or "bad file". Just stop printing when the end of data is reached. In the case of dwarf_getsrclines we would allocate a giant amount of memory, even if there was no data to actually read in. Sanity check that the directory and file counts seem reasonable compared to the amount of data left (assume we need at least 1 byte of data per form describing the dirs or files). Signed-off-by: Mark Wielaard <mark@klomp.org>
Diffstat (limited to 'libdw')
-rw-r--r--libdw/ChangeLog4
-rw-r--r--libdw/dwarf_getsrclines.c10
2 files changed, 14 insertions, 0 deletions
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 79fcf1ea..ddd82966 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,9 @@
2018-06-08 Mark Wielaard <mark@klomp.org>
+ * dwarf_getsrclines.c (read_srclines): Sanity check ndirs and nfiles.
+
+2018-06-08 Mark Wielaard <mark@klomp.org>
+
* dwarf_getlocation_attr.c (addr_valp): Set error and return NULL
when there is no .debug_addr section.
(dwarf_getlocation_attr): If addr_valp returns NULL, then return -1.
diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c
index 07baebcc..bb512ec6 100644
--- a/libdw/dwarf_getsrclines.c
+++ b/libdw/dwarf_getsrclines.c
@@ -356,6 +356,11 @@ read_srclines (Dwarf *dbg,
if (nforms == 0 && ndirs != 0)
goto invalid_data;
+
+ /* Assume there is at least 1 byte needed per form to describe
+ the directory. Filters out insanely large ndirs. */
+ if (nforms != 0 && ndirs > (size_t) (lineendp - linep) / nforms)
+ goto invalid_data;
}
/* Arrange the list in array form. */
@@ -561,6 +566,11 @@ read_srclines (Dwarf *dbg,
if (nforms == 0 && nfiles != 0)
goto invalid_data;
+ /* Assume there is at least 1 byte needed per form to describe
+ the file. Filters out insanely large nfiles. */
+ if (nforms != 0 && nfiles > (size_t) (lineendp - linep) / nforms)
+ goto invalid_data;
+
Dwarf_Attribute attr;
attr.cu = &fake_cu;
for (unsigned int n = 0; n < nfiles; n++)