* [COMMITTED] debugedit: Use standard libelf elf_strptr
@ 2022-04-20 22:12 Mark Wielaard
0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2022-04-20 22:12 UTC (permalink / raw)
To: debugedit; +Cc: Mark Wielaard
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 <mark@klomp.org>
---
tools/debugedit.c | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)
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 <mark@klomp.org>
Written by Alexander Larsson <alexl@redhat.com>, 2002
Based on code by Jakub Jelinek <jakub@redhat.com>, 2001.
String/Line table rewriting by Mark Wielaard <mjw@redhat.com>, 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);
}
--
2.30.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-04-20 22:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20 22:12 [COMMITTED] debugedit: Use standard libelf elf_strptr Mark Wielaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).