On Tue, 2015-04-07 at 18:34 +0200, Mark Wielaard wrote:
> On Mon, 2015-04-06 at 12:45 -0700, Roland McGrath wrote:
> > Usually "x + 1 >= y" should be "x > y", no?
> 
> Do you mean x >= y - 1?
> 
> The check is for whether there is a next element (x + 1) in the array
> (size y). If not the array will need extending. If there is such an
> element we check whether it already marks the end.
> 
> The bug was accessing that array element if it didn't exist to see
> whether we needed a new end marker. I am writing that as i + 1 >=
> dwfl->lookup_elts because if that is not true we'll access
> dwfl->lookup_addr[i + 1]. So the i + 1 check looks symmetric.
> 
> Or am I missing something?

I like to push this, because I believe it is correct and the current
code is wrong. But I don't know whether I am missing something. Please
let me know if you still think there is something obviously wrong with
the fix.

Thanks,

Mark
--- Begin Message ---
Caught by running run-backtrace-core-x32.sh under valgrind.

Signed-off-by: Mark Wielaard <[email protected]>
---
 libdwfl/ChangeLog | 4 ++++
 libdwfl/segment.c | 5 +++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index d40dbae..7664edc 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,7 @@
+2015-04-02  Mark Wielaard  <[email protected]>
+
+       * segment.c (insert): Check correct number of lookup_elts.
+
 2015-01-26  Mark Wielaard  <[email protected]>
 
        * dwfl_module_getdwarf.c (find_symtab): Explicitly clear symdata,
diff --git a/libdwfl/segment.c b/libdwfl/segment.c
index 9276917..2983cf2 100644
--- a/libdwfl/segment.c
+++ b/libdwfl/segment.c
@@ -1,5 +1,5 @@
 /* Manage address space lookup table for libdwfl.
-   Copyright (C) 2008, 2009, 2010, 2013 Red Hat, Inc.
+   Copyright (C) 2008, 2009, 2010, 2013, 2015 Red Hat, Inc.
    This file is part of elfutils.
 
    This file is free software; you can redistribute it and/or modify
@@ -50,7 +50,8 @@ static bool
 insert (Dwfl *dwfl, size_t i, GElf_Addr start, GElf_Addr end, int segndx)
 {
   bool need_start = (i == 0 || dwfl->lookup_addr[i - 1] != start);
-  bool need_end = (i >= dwfl->lookup_elts || dwfl->lookup_addr[i + 1] != end);
+  bool need_end = (i + 1 >= dwfl->lookup_elts
+                  || dwfl->lookup_addr[i + 1] != end);
   size_t need = need_start + need_end;
   if (need == 0)
     return false;
-- 
2.1.0


--- End Message ---

Reply via email to