diff options
author | Mark Wielaard <mark@klomp.org> | 2018-03-12 14:16:15 +0100 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2018-06-29 13:07:24 +0300 |
commit | f04f789ecd27db10922307879a67fff417dba440 (patch) | |
tree | 3fe62432dc7d50025edd51d7f6e4f1e33fc7f47d | |
parent | 531ac036b1e5eecc916b04ee8bb1472bc58a851d (diff) | |
download | rpm-f04f789ecd27db10922307879a67fff417dba440.tar.gz |
debugedit: Only try to collect comp_dir in phase zero.
edit_attributes is run twice. Once for phase zero in which all strings are
collected. Then then for phase one in which the strings are rewritten. In
phase zero we also try to collect the comp_dir (either from the
DW_AT_comp_dir or the DW_AT_name of the compile unit). We were also
collecting the comp_dir is phase 1, which is unnecessary, and would not
actually work, since we would be using to old string table index for that,
which had already been rewritten.
Caught by the new string table index checks.
Signed-off-by: Mark Wielaard <mark@klomp.org>
(cherry picked from commit ca5398ba242e25b4e167151194e36090d972b4c2)
-rw-r--r-- | tools/debugedit.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/tools/debugedit.c b/tools/debugedit.c index 6c71cbcbe..84568dd29 100644 --- a/tools/debugedit.c +++ b/tools/debugedit.c @@ -1539,14 +1539,18 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase) { const char *dir; size_t idx = do_read_32_relocated (ptr); - if (idx >= debug_sections[DEBUG_STR].size) - error (1, 0, - "%s: Bad string pointer index %zd for comp_dir", - dso->filename, idx); - dir = (char *) debug_sections[DEBUG_STR].data + idx; + /* In phase zero we collect the comp_dir. */ + if (phase == 0) + { + if (idx >= debug_sections[DEBUG_STR].size) + error (1, 0, + "%s: Bad string pointer index %zd for comp_dir", + dso->filename, idx); + dir = (char *) debug_sections[DEBUG_STR].data + idx; - free (comp_dir); - comp_dir = strdup (dir); + free (comp_dir); + comp_dir = strdup (dir); + } if (dest_dir != NULL && phase == 0) { @@ -1566,25 +1570,29 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase) unit. If starting with / it is a full path name. Note that we don't handle DW_FORM_string in this case. */ - char *name; size_t idx = do_read_32_relocated (ptr); - if (idx >= debug_sections[DEBUG_STR].size) - error (1, 0, - "%s: Bad string pointer index %zd for unit name", - dso->filename, idx); - name = (char *) debug_sections[DEBUG_STR].data + idx; - if (*name == '/' && comp_dir == NULL) - { - char *enddir = strrchr (name, '/'); - if (enddir != name) + /* In phase zero we will look for a comp_dir to use. */ + if (phase == 0) + { + if (idx >= debug_sections[DEBUG_STR].size) + error (1, 0, + "%s: Bad string pointer index %zd for unit name", + dso->filename, idx); + char *name = (char *) debug_sections[DEBUG_STR].data + idx; + if (*name == '/' && comp_dir == NULL) { - comp_dir = malloc (enddir - name + 1); - memcpy (comp_dir, name, enddir - name); - comp_dir [enddir - name] = '\0'; + char *enddir = strrchr (name, '/'); + + if (enddir != name) + { + comp_dir = malloc (enddir - name + 1); + memcpy (comp_dir, name, enddir - name); + comp_dir [enddir - name] = '\0'; + } + else + comp_dir = strdup ("/"); } - else - comp_dir = strdup ("/"); } /* First pass (0) records the new name to be |