This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
[PATCH] libdwfl: Correct off-by-one check in segment.c insert.
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Thu, 02 Apr 2015 13:39:03 +0200
- Subject: [PATCH] libdwfl: Correct off-by-one check in segment.c insert.
Caught by running run-backtrace-core-x32.sh under valgrind.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
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 <mjw@redhat.com>
+
+ * segment.c (insert): Check correct number of lookup_elts.
+
2015-01-26 Mark Wielaard <mjw@redhat.com>
* 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