]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libelf: Make sure version xlate dest buffer is fully defined.
authorMark Wielaard <mjw@redhat.com>
Sat, 3 Jan 2015 22:02:17 +0000 (23:02 +0100)
committerMark Wielaard <mjw@redhat.com>
Wed, 6 May 2015 11:43:22 +0000 (13:43 +0200)
https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c16
contains an example of usage of undefined memory when version section
data needs to be translated, but the version xlate functions detect they
cannot fully transform the section data. To make sure the dest buffer
data is completely defined this patch makes sure all data is moved
from src to dest first. This is somewhat inefficient since normally
all data will be fully converted. But the translation functions have
no way to indicate only partial data was converted.

Reported-by: Alexander Cherepanov <cherepan@mccme.ru>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf/ChangeLog
libelf/version_xlate.h

index a1b0ee4a76086cd7786a9a5f29a78d8603ee20e6..e9c2a8deb140dd5f5678567f209de2c4b433480f 100644 (file)
@@ -1,3 +1,8 @@
+2015-01-03  Mark Wielaard  <mjw@redhat.com>
+
+       * version_xlate.h (elf_cvt_Verdef): Use memmove to copy src to dest.
+       (elf_cvt_Verneed): Likewise.
+
 2015-03-28  Mark Wielaard  <mjw@redhat.com>
 
        * elf.h: Update from glibc.
index 16eaa19cd750f1176818bcf3d053839afcca9122..9fe01c6419ec133b70970cbcf1f0512ae3462a64 100644 (file)
@@ -1,5 +1,5 @@
 /* Conversion functions for versioning information.
-   Copyright (C) 1998, 1999, 2000, 2002, 2003 Red Hat, Inc.
+   Copyright (C) 1998, 1999, 2000, 2002, 2003, 2015 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 1998.
 
@@ -55,6 +55,11 @@ elf_cvt_Verdef (void *dest, const void *src, size_t len, int encode)
   if (len == 0)
     return;
 
+  /* Below we rely on the next field offsets to be correct, start by
+     copying over all data as is in case some data isn't translated.
+     We don't want to leave (undefined) garbage in the dest buffer.  */
+  memmove (dest, src, len);
+
   do
     {
       size_t aux_offset;
@@ -149,6 +154,11 @@ elf_cvt_Verneed (void *dest, const void *src, size_t len, int encode)
   if (len == 0)
     return;
 
+  /* Below we rely on the next field offsets to be correct, start by
+     copying over all data as is in case some data isn't translated.
+     We don't want to leave (undefined) garbage in the dest buffer.  */
+  memmove (dest, src, len);
+
   do
     {
       size_t aux_offset;