[pan2] Fix error found by valgrind: Invalid read of size 1



commit 3ed2498e8a68bdfaed4a38dca0b440565d528e40
Author: Olaf Seibert <rhialto falu nl>
Date:   Tue Mar 22 00:49:17 2016 +0100

    Fix error found by valgrind: Invalid read of size 1
    
    (hopefully; I'm not sure which article triggered it)
    
       at 0x55D318: pan::url_find(pan::StringView const&, pan::StringView&) (url-find.cc:83)
       by 0x47CB6E: append_text_buffer_nolock (body-pane.cc:884)
       by 0x47CB6E: pan::BodyPane::append_part(_GMimeObject*, _GMimeObject*, _GdkRectangle*) 
(body-pane.cc:1047)
       by 0x47D8FF: pan::BodyPane::foreach_part_cb(_GMimeObject*, _GMimeObject*, void*) (body-pane.cc:1071)
       by 0x7904CD1: g_mime_message_foreach (in /usr/lib/x86_64-linux-gnu/libgmime-2.6.so.0.620.0)
       by 0x47E3BB: pan::BodyPane::set_text_from_message(_GMimeMessage*) (body-pane.cc:1268)
       by 0x463AEB: pan::GUI::root_realized_cb(_GtkWidget*, void*) (gui.cc:210)
    ...
       by 0x52906B5: gtk_widget_show (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.28)
       by 0x476399: run_pan_in_window (pan.cc:530)
       by 0x476399: main (pan.cc:1109)
     Address 0x1067deef is 1 bytes before a block of size 338,231 alloc'd
       at 0x4C2C12F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
       by 0x808C988: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> 
::_M_mutate(unsigned long, unsigned long, char const*, unsigned long) (in 
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
       by 0x808D4FA: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> 
::_M_replace(unsigned long, unsigned long, char const*, unsigned long) (in 
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21)
       by 0x47C1BC: assign (basic_string.h:1149)
       by 0x47C1BC: append_text_buffer_nolock (body-pane.cc:767)
       by 0x47C1BC: pan::BodyPane::append_part(_GMimeObject*, _GMimeObject*, _GdkRectangle*) 
(body-pane.cc:1047)
       by 0x47D8FF: pan::BodyPane::foreach_part_cb(_GMimeObject*, _GMimeObject*, void*) (body-pane.cc:1071)
       by 0x7904CD1: g_mime_message_foreach (in /usr/lib/x86_64-linux-gnu/libgmime-2.6.so.0.620.0)
       by 0x47E3BB: pan::BodyPane::set_text_from_message(_GMimeMessage*) (body-pane.cc:1268)
       by 0x463AEB: pan::GUI::root_realized_cb(_GtkWidget*, void*) (gui.cc:210)
       by 0x6A9D014: g_closure_invoke (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4600.2)
    ...
       by 0x52906B5: gtk_widget_show (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.28)
       by 0x476399: run_pan_in_window (pan.cc:530)
       by 0x476399: main (pan.cc:1109)

 pan/usenet-utils/url-find.cc |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/pan/usenet-utils/url-find.cc b/pan/usenet-utils/url-find.cc
index 28ef4c8..7424ee6 100644
--- a/pan/usenet-utils/url-find.cc
+++ b/pan/usenet-utils/url-find.cc
@@ -79,9 +79,11 @@ pan :: url_find (const StringView& text, StringView& setme_url)
   // for urls at the end of a sentence.
   if (!setme_url.empty() && strchr("?!.,", setme_url.back()))
     --setme_url.len;
-  const char c = text.str[ start - 1 ];
-  if (c == '\'' && c == setme_url.back() )
-    --setme_url.len;
+  if (start > 0) {
+    const char c = text.str[ start - 1 ];
+    if (c == '\'' && c == setme_url.back() )
+      --setme_url.len;
+  }
   return true;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]