Skip to content

Commit

Permalink
Reject requests for abbreviation with code 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Machata committed Mar 10, 2011
1 parent d76bd7a commit 02c5619
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 5 deletions.
5 changes: 5 additions & 0 deletions libdw/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2011-03-10 Petr Machata <[email protected]>

* libdw/dwarf_tag.c (__libdw_findabbrev): Reject requests for
abbreviation with code 0.

2011-03-09 Petr Machata <[email protected]>

* libdw/dwarf_child.c (dwarf_child): Check for section overrun.
Expand Down
6 changes: 5 additions & 1 deletion libdw/dwarf_tag.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Return tag of given DIE.
Copyright (C) 2003, 2004, 2005, 2006, 2008 Red Hat, Inc.
Copyright (C) 2003-2011 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <[email protected]>, 2003.
Expand Down Expand Up @@ -61,6 +61,10 @@ __libdw_findabbrev (struct Dwarf_CU *cu, unsigned int code)
{
Dwarf_Abbrev *abb;

/* Abbreviation code can never have a value of 0. */
if (unlikely (code == 0))
return DWARF_END_ABBREV;

/* See whether the entry is already in the hash table. */
abb = Dwarf_Abbrev_Hash_find (&cu->abbrev_hash, code, NULL);
if (abb == NULL)
Expand Down
10 changes: 6 additions & 4 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Process this file with automake to create Makefile.in
##
## Copyright (C) 1996-2010 Red Hat, Inc.
## Copyright (C) 1996-2011 Red Hat, Inc.
## This file is part of Red Hat elfutils.
##
## Red Hat elfutils is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -57,7 +57,7 @@ noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
dwfl-bug-addr-overflow arls dwfl-bug-fd-leak \
dwfl-addr-sect dwfl-bug-report early-offscn \
dwfl-bug-getmodules dwarf-getmacros addrcfi \
test-flag-nobits dwarf-getstring
test-flag-nobits dwarf-getstring rerequest_tag
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
asm-tst6 asm-tst7 asm-tst8 asm-tst9

Expand All @@ -84,7 +84,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
run-disasm-x86.sh run-disasm-x86-64.sh \
run-early-offscn.sh run-dwarf-getmacros.sh \
run-test-flag-nobits.sh run-prelink-addr-test.sh \
run-dwarf-getstring.sh
run-dwarf-getstring.sh run-rerequest_tag.sh
# run-show-ciefde.sh

if !STANDALONE
Expand Down Expand Up @@ -156,7 +156,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
testfile54-64.prelink.so.bz2 testfile54-64.noshdrs.so.bz2 \
testfile55-32.bz2 testfile55-32.debug.bz2 \
testfile55-32.prelink.bz2 testfile55-64.bz2 \
testfile55-64.debug.bz2 testfile55-64.prelink.bz2
testfile55-64.debug.bz2 testfile55-64.prelink.bz2 \
testfile56.bz2

installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \
bindir=$(DESTDIR)$(bindir) \
Expand Down Expand Up @@ -251,6 +252,7 @@ dwarf_getmacros_LDADD = $(libdw) $(libmudflap)
dwarf_getstring_LDADD = $(libdw) $(libmudflap)
addrcfi_LDADD = $(libdw) $(libebl) $(libelf) $(libmudflap) -ldl
test_flag_nobits_LDADD = $(libelf) $(libmudflap)
rerequest_tag_LDADD = $(libdw) $(libmudflap)

if GCOV
check: check-am coverage
Expand Down
53 changes: 53 additions & 0 deletions tests/rerequest_tag.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright (C) 2011 Red Hat, Inc.
This file is part of Red Hat elfutils.
Red Hat elfutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the
Free Software Foundation; version 2 of the License.
Red Hat elfutils is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with Red Hat elfutils; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
Red Hat elfutils is an included package of the Open Invention Network.
An included package of the Open Invention Network is a package for which
Open Invention Network licensees cross-license their patents. No patent
license is granted, either expressly or impliedly, by designation as an
included package. Should you wish to participate in the Open Invention
Network licensing program, please visit www.openinventionnetwork.com
<http://www.openinventionnetwork.com>. */

#include <config.h>

#include ELFUTILS_HEADER(dw)
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

int main(int argc, char *argv[])
{
assert (argc > 1);

int i = open(argv[1], O_RDONLY);
assert (i >= 0);

Dwarf *dw = dwarf_begin(i, DWARF_C_READ);
assert (dw != NULL);

Dwarf_Die die_mem, *die;
die = dwarf_offdie (dw, 11, &die_mem);
assert (die == &die_mem);
assert (dwarf_tag (die) == 0);

die = dwarf_offdie (dw, 11, &die_mem);
assert (die == &die_mem);
assert (dwarf_tag (die) == 0);

return 0;
}
33 changes: 33 additions & 0 deletions tests/run-rerequest_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /bin/sh
# Copyright (C) 2011 Red Hat, Inc.
# This file is part of Red Hat elfutils.
#
# Red Hat elfutils is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; version 2 of the License.
#
# Red Hat elfutils is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Red Hat elfutils; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
#
# Red Hat elfutils is an included package of the Open Invention Network.
# An included package of the Open Invention Network is a package for which
# Open Invention Network licensees cross-license their patents. No patent
# license is granted, either expressly or impliedly, by designation as an
# included package. Should you wish to participate in the Open Invention
# Network licensing program, please visit www.openinventionnetwork.com
# <http://www.openinventionnetwork.com>.

. $srcdir/test-subr.sh

testfiles testfile56

testrun_compare ./rerequest_tag testfile56 <<\EOF
EOF

exit 0
Binary file added tests/testfile56.bz2
Binary file not shown.

0 comments on commit 02c5619

Please sign in to comment.