From: Mark Wielaard <mark@klomp.org>
To: debugedit@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [COMMITTED] debugedit: Use standard libelf elf_strptr
Date: Thu, 21 Apr 2022 00:12:34 +0200 [thread overview]
Message-ID: <20220420221234.219657-1-mark@klomp.org> (raw)
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
reply other threads:[~2022-04-20 22:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220420221234.219657-1-mark@klomp.org \
--to=mark@klomp.org \
--cc=debugedit@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).