When d_size is zero d_buf might be NULL. last_position doesn't need to be
updated in that case.

Signed-off-by: Mark Wielaard <[email protected]>
---
 libelf/ChangeLog          | 5 +++++
 libelf/elf32_updatefile.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index 5f66135..b8c20cc 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2015-05-30  Mark Wielaard  <[email protected]>
+
+       * elf32_updatefile.c (updatemmap): Only call mempcpy and update
+       last_position when d_size is non-zero.
+
 2015-05-17  Mark Wielaard  <[email protected]>
 
        * elf32_updatefile.c (updatefile): Allocate shdr_data and scns
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index e90ad47..913c3e4 100644
--- a/libelf/elf32_updatefile.c
+++ b/libelf/elf32_updatefile.c
@@ -367,7 +367,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, 
size_t shnum)
 
                        last_position += dl->data.d.d_size;
                      }
-                   else
+                   else if (dl->data.d.d_size != 0)
                      last_position = mempcpy (last_position,
                                               dl->data.d.d_buf,
                                               dl->data.d.d_size);
-- 
2.1.0

Reply via email to