From 7599691dd1369d81ccf9cb9f0e98607725f712b4 Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Tue, 27 Mar 2018 21:38:58 -0700 Subject: [PATCH] dwarfindex: don't check that strp is null-terminated If we make sure .debug_str is null-terminated, we just need to make sure strp is not out of bounds. --- drgn/dwarfindex.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drgn/dwarfindex.c b/drgn/dwarfindex.c index ed846651..cc818aa5 100644 --- a/drgn/dwarfindex.c +++ b/drgn/dwarfindex.c @@ -881,10 +881,7 @@ sibling_ref: return -1; } name = &debug_str_buffer[strp]; - if (!memchr(name, 0, debug_str_end - name)) { - PyErr_SetNone(PyExc_EOFError); - return -1; - } + __builtin_prefetch(name); continue; case DW_FORM_string: if (*ptr >= end) { @@ -1079,6 +1076,7 @@ static int DwarfIndex_init(DwarfIndex *self, PyObject *args, PyObject *kwds) } for (i = 0; i < self->num_files; i++) { + const struct section *debug_str; PyObject *path; size_t j; @@ -1107,6 +1105,14 @@ static int DwarfIndex_init(DwarfIndex *self, PyObject *args, PyObject *kwds) return -1; } + debug_str = &self->files[i].debug_sections[DEBUG_STR]; + if (debug_str->size == 0 || + debug_str->buffer[debug_str->size - 1] != '\0') { + PyErr_SetString(DwarfFormatError, + ".debug_str is not null terminated"); + return -1; + } + if (read_cus(self, &self->files[i]) == -1) return -1;