From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============1149111392859286322==" MIME-Version: 1.0 From: Thilo Schulz To: elfutils-devel@lists.fedorahosted.org Subject: [PATCH] Fix section corruption bug Date: Mon, 09 Jun 2014 21:05:50 +0200 Message-ID: <20140609190550.GE14956@toonder.wildebeest.org> --===============1149111392859286322== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Hi, When adding data to existing sections in ELF files, libelf may corrupt those sections, i.e. overwrite the existing data if certain conditions are met. If an Elf_Scn structure has seen a call to elf_rawdata(scn) before but no call to elf_getdata(scn), scn->read_data flag is set, but not scn->data_list_rear. Thus, elf_newdata(scn) incorrectly detects a "new user added section" when really it is a section with live, valid data that will be overwritten by elf_update(), corrupting the section. This patch fixes this incorrect behaviour. Signed-off-by: Thilo Schulz --- libelf/elf_newdata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libelf/elf_newdata.c b/libelf/elf_newdata.c index 90d1813..f90eb0a 100644 --- a/libelf/elf_newdata.c +++ b/libelf/elf_newdata.c @@ -64,7 +64,7 @@ elf_newdata (Elf_Scn *scn) = rwlock_wrlock (scn->elf->lock); = - if (scn->data_read && scn->data_list_rear =3D=3D NULL) + if (scn->data_read && scn->data_list_rear =3D=3D NULL && !scn->rawdata.s) { /* This means the section was created by the user and this is the first data. */ -- = 1.7.10.4 --===============1149111392859286322==--