[glom] glom/dialog_import_csv.cc: get_data(): Avoid out-of-bounds crashes



commit 183b6f2b365fb03bff0cf48904b13c5d92ee3385
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Sep 21 10:24:27 2009 +0200

    glom/dialog_import_csv.cc: get_data(): Avoid out-of-bounds crashes
    when accessing the vector of vectors. Note that this check is
    already in the appropriate place in the import_csv_refactored branch.
    This makes bug #593304 slighly clearer, though it is now an endless
    loop with debug output.

 ChangeLog                      |    8 ++++++++
 glom/dialog_import_csv.cc      |   17 ++++++++++++++++-
 glom/libglom/connectionpool.cc |    2 +-
 3 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 3d8ce81..dc851c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2009-09-21  Murray Cumming  <murrayc murrayc com>
 
+	* glom/dialog_import_csv.cc: get_data(): Avoid out-of-bounds crashes 
+	when accessing the vector of vectors. Note that this check is 
+	already in the appropriate place in the import_csv_refactored branch.
+	This makes bug #593304 slighly clearer, though it is now an endless 
+	loop with debug output.
+
+2009-09-21  Murray Cumming  <murrayc murrayc com>
+
 	Import dialog: Set the number of sample rows to 2 by default.
 
 	* glom/dialog_import_csv.cc: Set the number of sample rows to 2 
diff --git a/glom/dialog_import_csv.cc b/glom/dialog_import_csv.cc
index c3113c3..9415aff 100644
--- a/glom/dialog_import_csv.cc
+++ b/glom/dialog_import_csv.cc
@@ -278,7 +278,22 @@ const Glib::ustring& Dialog_Import_CSV::get_data(guint row, guint col)
   if(m_first_line_as_title->get_active())
     ++row;
 
-  return m_parser->m_rows[row][col];
+  static Glib::ustring empty_result;
+
+  if(row >= m_parser->m_rows.size())
+  {
+    std::cerr << "Dialog_Import_CSV::get_data(): row out of range." << std::endl;
+    return empty_result;
+  }
+
+  const CsvParser::type_row_strings& row_data = m_parser->m_rows[row];
+  if(col >= row_data.size())
+  {
+    std::cerr << "Dialog_Import_CSV::get_data(): col out of range." << std::endl;
+    return empty_result;
+  }
+
+  return row_data[col];
 }
 
 void Dialog_Import_CSV::clear()
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index b5bf139..73a7bf1 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -644,7 +644,7 @@ bool ConnectionPool::startup(const SlotProgress& slot_progress, bool network_sha
 
   //If we crash while running (unlikely, hopefully), then try to cleanup.
   //Comment this out if you want to see the backtrace in a debugger.
-  previous_sig_handler = signal(SIGSEGV, &on_linux_signal);
+  //previous_sig_handler = signal(SIGSEGV, &on_linux_signal);
 
   return true;
 }



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