From: Mark Wielaard Date: Wed, 20 Apr 2022 22:05:38 +0000 (+0200) Subject: debugedit: Use standard libelf elf_strptr X-Git-Tag: debugedit-5.1~37 X-Git-Url: https://www.sourceware.org/git/?a=commitdiff_plain;h=7497274aed00c459a0d74bf171e1b11358b0210c;p=debugedit.git debugedit: Use standard libelf elf_strptr The strptr function in debugedit.c does the same thing as libelf elf_strptr. But elf_strptr handles bounds checks and invalid section offsets better. And elf_strptr handles compressed sections. * tools/debugedit.c (strptr): Just call elf_strptr. Signed-off-by: Mark Wielaard --- diff --git a/tools/debugedit.c b/tools/debugedit.c index e734dd7..d82ae5a 100644 --- a/tools/debugedit.c +++ b/tools/debugedit.c @@ -1,4 +1,5 @@ /* Copyright (C) 2001-2003, 2005, 2007, 2009-2011, 2016, 2017 Red Hat, Inc. + Copyright (C) 2022 Mark J. Wielaard Written by Alexander Larsson , 2002 Based on code by Jakub Jelinek , 2001. String/Line table rewriting by Mark Wielaard , 2017. @@ -295,25 +296,9 @@ buf_read_ube32 (unsigned char *data) } static const char * -strptr (DSO *dso, int sec, off_t offset) +strptr (DSO *dso, size_t sec, size_t offset) { - Elf_Scn *scn; - Elf_Data *data; - - scn = dso->scn[sec]; - if (offset >= 0 && (GElf_Addr) offset < dso->shdr[sec].sh_size) - { - data = NULL; - while ((data = elf_getdata (scn, data)) != NULL) - { - if (data->d_buf - && offset >= data->d_off - && offset < data->d_off + data->d_size) - return (const char *) data->d_buf + (offset - data->d_off); - } - } - - return NULL; + return elf_strptr (dso->elf, sec, offset); }