blob: c83c8b5f3fcb274029ca6d8e441b9a33fda3a83f [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001During the recalculation of the buildid, it's necessary to change the word
2back to the original endian. However, if we do this in-place, we've also
3affected the headers that we're also working on. The side effect of this is
4we can no longer rely on 'sh_type' as it may have been changed.
5
6This patch ensures that any time we translate the loaded data to the machine
7format, we only do it in a backup copy and never the original copy.
8
9Note: in all other places a backup copy was used, just not buildid processing.
10
11Also the process (...) function was modified to verify the data is not
12NULL as well. This is an extra check and is not strictly necessary.
13
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050014Upstream-Status: Submitted [RPM5 maintainer]
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015
16Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
17
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050018Index: rpm/tools/debugedit.c
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019===================================================================
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050020--- rpm.orig/tools/debugedit.c
21+++ rpm/tools/debugedit.c
22@@ -1403,7 +1403,8 @@ static inline void process (hashFunction
23 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
31 /* Compute a fresh build ID bit-string from the editted file contents. */
32@@ -1456,14 +1457,16 @@ handle_build_id (DSO *dso, Elf_Data *bui
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033 GElf_Ehdr ehdr;
34 GElf_Phdr phdr;
35 GElf_Shdr shdr;
36- } u;
37- Elf_Data x = { .d_version = EV_CURRENT, .d_buf = &u };
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050038-
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039- x.d_type = ELF_T_EHDR;
40- x.d_size = sizeof u.ehdr;
41- u.ehdr = dso->ehdr;
42- u.ehdr.e_phoff = u.ehdr.e_shoff = 0;
43- if (elf64_xlatetom (&x, &x, dso->ehdr.e_ident[EI_DATA]) == NULL)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050044+ } u1, u2;
45+ Elf_Data src = { .d_version = EV_CURRENT, .d_buf = &u1 };
46+ Elf_Data dest = { .d_version = EV_CURRENT, .d_buf = &u2 };
47+
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048+ src.d_type = ELF_T_EHDR;
49+ src.d_size = sizeof u1.ehdr;
50+ dest.d_size = sizeof u2.ehdr;
51+ u1.ehdr = dso->ehdr;
52+ u1.ehdr.e_phoff = u1.ehdr.e_shoff = 0;
53+ if (elf64_xlatetom (&dest, &src, dso->ehdr.e_ident[EI_DATA]) == NULL)
54 {
55 bad:
56 fprintf (stderr, "Failed to compute header checksum: %s\n",
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050057@@ -1471,29 +1474,31 @@ handle_build_id (DSO *dso, Elf_Data *bui
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058 exit (1);
59 }
60
61- x.d_type = ELF_T_PHDR;
62- x.d_size = sizeof u.phdr;
63+ src.d_type = ELF_T_PHDR;
64+ src.d_size = sizeof u1.phdr;
65+ dest.d_size = sizeof u2.phdr;
66 for (i = 0; i < dso->ehdr.e_phnum; ++i)
67 {
68- if (gelf_getphdr (dso->elf, i, &u.phdr) == NULL)
69+ if (gelf_getphdr (dso->elf, i, &u1.phdr) == NULL)
70 goto bad;
71- if (elf64_xlatetom (&x, &x, dso->ehdr.e_ident[EI_DATA]) == NULL)
72+ if (elf64_xlatetom (&dest, &src, dso->ehdr.e_ident[EI_DATA]) == NULL)
73 goto bad;
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050074- process (&ctx, x.d_buf, x.d_size);
75+ process (&ctx, dest.d_buf, dest.d_size);
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076 }
77
78- x.d_type = ELF_T_SHDR;
79- x.d_size = sizeof u.shdr;
80+ src.d_type = ELF_T_SHDR;
81+ src.d_size = sizeof u1.shdr;
82+ dest.d_size = sizeof u2.shdr;
83 for (i = 0; i < dso->ehdr.e_shnum; ++i)
84 if (dso->scn[i] != NULL)
85 {
86- u.shdr = dso->shdr[i];
87- u.shdr.sh_offset = 0;
88- if (elf64_xlatetom (&x, &x, dso->ehdr.e_ident[EI_DATA]) == NULL)
89+ u1.shdr = dso->shdr[i];
90+ u1.shdr.sh_offset = 0;
91+ if (elf64_xlatetom (&dest, &src, dso->ehdr.e_ident[EI_DATA]) == NULL)
92 goto bad;
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050093- process (&ctx, x.d_buf, x.d_size);
94+ process (&ctx, dest.d_buf, dest.d_size);
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095
96- if (u.shdr.sh_type != SHT_NOBITS)
97+ if (u1.shdr.sh_type != SHT_NOBITS)
98 {
99 Elf_Data *d = elf_rawdata (dso->scn[i], NULL);
100 if (d == NULL)