Blame SOURCES/elfutils-0.174-libdwfl-sanity-check-core-reads.patch

95a93d
commit 20f9de9b5f704cec55df92406a50bcbcfca96acd
95a93d
Author: Mark Wielaard <mark@klomp.org>
95a93d
Date:   Sun Oct 14 16:45:48 2018 +0200
95a93d
95a93d
    libdwfl: Sanity check partial core file data reads.
95a93d
    
95a93d
    There were two issues when reading note data from a core file.
95a93d
    We didn't check if the data we already had in a buffer was big
95a93d
    enough. And if we did get the data, we should check if we got
95a93d
    everything, or just a part of the data.
95a93d
    
95a93d
    https://sourceware.org/bugzilla/show_bug.cgi?id=23752
95a93d
    
95a93d
    Signed-off-by: Mark Wielaard <mark@klomp.org>
95a93d
95a93d
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
95a93d
index 36e5c82..8749884 100644
95a93d
--- a/libdwfl/dwfl_segment_report_module.c
95a93d
+++ b/libdwfl/dwfl_segment_report_module.c
95a93d
@@ -1,5 +1,5 @@
95a93d
 /* Sniff out modules from ELF headers visible in memory segments.
95a93d
-   Copyright (C) 2008-2012, 2014, 2015 Red Hat, Inc.
95a93d
+   Copyright (C) 2008-2012, 2014, 2015, 2018 Red Hat, Inc.
95a93d
    This file is part of elfutils.
95a93d
 
95a93d
    This file is free software; you can redistribute it and/or modify
95a93d
@@ -301,7 +301,10 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
95a93d
   inline bool read_portion (void **data, size_t *data_size,
95a93d
 			    GElf_Addr vaddr, size_t filesz)
95a93d
   {
95a93d
-    if (vaddr - start + filesz > buffer_available
95a93d
+    /* Check whether we will have to read the segment data, or if it
95a93d
+       can be returned from the existing buffer.  */
95a93d
+    if (filesz > buffer_available
95a93d
+	|| vaddr - start > buffer_available - filesz
95a93d
 	/* If we're in string mode, then don't consider the buffer we have
95a93d
 	   sufficient unless it contains the terminator of the string.  */
95a93d
 	|| (filesz == 0 && memchr (vaddr - start + buffer, '\0',
95a93d
@@ -459,6 +462,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
95a93d
     if (read_portion (&data, &data_size, vaddr, filesz))
95a93d
       return;
95a93d
 
95a93d
+    /* data_size will be zero if we got everything from the initial
95a93d
+       buffer, otherwise it will be the size of the new buffer that
95a93d
+       could be read.  */
95a93d
+    if (data_size != 0)
95a93d
+      filesz = data_size;
95a93d
+
95a93d
     assert (sizeof (Elf32_Nhdr) == sizeof (Elf64_Nhdr));
95a93d
 
95a93d
     void *notes;