Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | During the recalculation of the buildid, it's necessary to change the word |
| 2 | back to the original endian. However, if we do this in-place, we've also |
| 3 | affected the headers that we're also working on. The side effect of this is |
| 4 | we can no longer rely on 'sh_type' as it may have been changed. |
| 5 | |
| 6 | This patch ensures that any time we translate the loaded data to the machine |
| 7 | format, we only do it in a backup copy and never the original copy. |
| 8 | |
| 9 | Note: in all other places a backup copy was used, just not buildid processing. |
| 10 | |
| 11 | Also the process (...) function was modified to verify the data is not |
| 12 | NULL as well. This is an extra check and is not strictly necessary. |
| 13 | |
| 14 | Upstream-Status: Pending |
| 15 | |
| 16 | Signed-off-by: Mark Hatle <mark.hatle@windriver.com> |
| 17 | |
| 18 | Index: rpm-5.4.14/tools/debugedit.c |
| 19 | =================================================================== |
| 20 | --- rpm-5.4.14.orig/tools/debugedit.c |
| 21 | +++ rpm-5.4.14/tools/debugedit.c |
| 22 | @@ -1445,21 +1445,24 @@ handle_build_id (DSO *dso, Elf_Data *bui |
| 23 | auto inline void process (const void *data, size_t size) |
| 24 | { |
| 25 | memchunk chunk = { .data = (void *) data, .size = size }; |
| 26 | - hashFunctionContextUpdateMC (&ctx, &chunk); |
| 27 | + if (data != NULL && size != 0) |
| 28 | + hashFunctionContextUpdateMC (&ctx, &chunk); |
| 29 | } |
| 30 | union |
| 31 | { |
| 32 | GElf_Ehdr ehdr; |
| 33 | GElf_Phdr phdr; |
| 34 | GElf_Shdr shdr; |
| 35 | - } u; |
| 36 | - Elf_Data x = { .d_version = EV_CURRENT, .d_buf = &u }; |
| 37 | + } u1, u2; |
| 38 | + Elf_Data src = { .d_version = EV_CURRENT, .d_buf = &u1 }; |
| 39 | + Elf_Data dest = { .d_version = EV_CURRENT, .d_buf = &u2 }; |
| 40 | |
| 41 | - x.d_type = ELF_T_EHDR; |
| 42 | - x.d_size = sizeof u.ehdr; |
| 43 | - u.ehdr = dso->ehdr; |
| 44 | - u.ehdr.e_phoff = u.ehdr.e_shoff = 0; |
| 45 | - if (elf64_xlatetom (&x, &x, dso->ehdr.e_ident[EI_DATA]) == NULL) |
| 46 | + src.d_type = ELF_T_EHDR; |
| 47 | + src.d_size = sizeof u1.ehdr; |
| 48 | + dest.d_size = sizeof u2.ehdr; |
| 49 | + u1.ehdr = dso->ehdr; |
| 50 | + u1.ehdr.e_phoff = u1.ehdr.e_shoff = 0; |
| 51 | + if (elf64_xlatetom (&dest, &src, dso->ehdr.e_ident[EI_DATA]) == NULL) |
| 52 | { |
| 53 | bad: |
| 54 | fprintf (stderr, "Failed to compute header checksum: %s\n", |
| 55 | @@ -1467,29 +1470,31 @@ handle_build_id (DSO *dso, Elf_Data *bui |
| 56 | exit (1); |
| 57 | } |
| 58 | |
| 59 | - x.d_type = ELF_T_PHDR; |
| 60 | - x.d_size = sizeof u.phdr; |
| 61 | + src.d_type = ELF_T_PHDR; |
| 62 | + src.d_size = sizeof u1.phdr; |
| 63 | + dest.d_size = sizeof u2.phdr; |
| 64 | for (i = 0; i < dso->ehdr.e_phnum; ++i) |
| 65 | { |
| 66 | - if (gelf_getphdr (dso->elf, i, &u.phdr) == NULL) |
| 67 | + if (gelf_getphdr (dso->elf, i, &u1.phdr) == NULL) |
| 68 | goto bad; |
| 69 | - if (elf64_xlatetom (&x, &x, dso->ehdr.e_ident[EI_DATA]) == NULL) |
| 70 | + if (elf64_xlatetom (&dest, &src, dso->ehdr.e_ident[EI_DATA]) == NULL) |
| 71 | goto bad; |
| 72 | - process (x.d_buf, x.d_size); |
| 73 | + process (dest.d_buf, dest.d_size); |
| 74 | } |
| 75 | |
| 76 | - x.d_type = ELF_T_SHDR; |
| 77 | - x.d_size = sizeof u.shdr; |
| 78 | + src.d_type = ELF_T_SHDR; |
| 79 | + src.d_size = sizeof u1.shdr; |
| 80 | + dest.d_size = sizeof u2.shdr; |
| 81 | for (i = 0; i < dso->ehdr.e_shnum; ++i) |
| 82 | if (dso->scn[i] != NULL) |
| 83 | { |
| 84 | - u.shdr = dso->shdr[i]; |
| 85 | - u.shdr.sh_offset = 0; |
| 86 | - if (elf64_xlatetom (&x, &x, dso->ehdr.e_ident[EI_DATA]) == NULL) |
| 87 | + u1.shdr = dso->shdr[i]; |
| 88 | + u1.shdr.sh_offset = 0; |
| 89 | + if (elf64_xlatetom (&dest, &src, dso->ehdr.e_ident[EI_DATA]) == NULL) |
| 90 | goto bad; |
| 91 | - process (x.d_buf, x.d_size); |
| 92 | + process (dest.d_buf, dest.d_size); |
| 93 | |
| 94 | - if (u.shdr.sh_type != SHT_NOBITS) |
| 95 | + if (u1.shdr.sh_type != SHT_NOBITS) |
| 96 | { |
| 97 | Elf_Data *d = elf_rawdata (dso->scn[i], NULL); |
| 98 | if (d == NULL) |