/* Return child of current DIE.
- Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Red Hat, Inc.
+ Copyright (C) 2003-2011 Red Hat, Inc.
This file is part of Red Hat elfutils.
Written by Ulrich Drepper <drepper@redhat.com>, 2003.
if (addr == NULL)
return -1;
+ /* RESULT can be the same as DIE. So preserve what we need. */
+ struct Dwarf_CU *cu = die->cu;
+
/* It's kosher (just suboptimal) to have a null entry first thing (7.5.3).
So if this starts with ULEB128 of 0 (even with silly encoding of 0),
it is a kosher null entry and we do not really have any children. */
const unsigned char *code = addr;
- while (unlikely (*code == 0x80))
- ++code;
+ const unsigned char *endp = (cu->dbg->sectiondata[IDX_debug_info]->d_buf
+ + cu->dbg->sectiondata[IDX_debug_info]->d_size);
+ while (1)
+ {
+ if (unlikely (code >= endp)) /* Truncated section. */
+ return 1;
+ if (unlikely (*code == 0x80))
+ ++code;
+ else
+ break;
+ }
if (unlikely (*code == '\0'))
return 1;
- /* RESULT can be the same as DIE. So preserve what we need. */
- struct Dwarf_CU *cu = die->cu;
-
/* Clear the entire DIE structure. This signals we have not yet
determined any of the information. */
memset (result, '\0', sizeof (Dwarf_Die));