octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #63437] Null pointer dereference in file-edito


From: Arun Giridhar
Subject: [Octave-bug-tracker] [bug #63437] Null pointer dereference in file-editor-tab.cc
Date: Mon, 28 Nov 2022 17:05:44 -0500 (EST)

URL:
  <https://savannah.gnu.org/bugs/?63437>

                 Summary: Null pointer dereference in file-editor-tab.cc
                 Project: GNU Octave
               Submitter: arungiridhar
               Submitted: Mon 28 Nov 2022 05:05:41 PM EST
                Category: GUI
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Segfault, Bus Error, etc.
                  Status: Patch Submitted
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
                 Release: stable
         Discussion Lock: Any
        Operating System: Any
           Fixed Release: None
         Planned Release: 8.1.0 (current stable)


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Mon 28 Nov 2022 05:05:41 PM EST By: Arun Giridhar <arungiridhar>
A static analyzer found a null pointer dereference with this code in
file-editor-tab.cc:

   270      gui_settings *settings = rmgr.get_settings ();
   271      if (settings)
   272        notice_settings (settings, true);
   273  
   274      // encoding, not updated with the settings
   275      m_encoding = settings->value (ed_default_enc.key, "UTF-8").toString
();


The problem is that `settings` is being checked for nullptr for only the
`notice_settings` use but not for the `m_encoding = settings->value` use, so
the second case could potentially dereference a nullptr.

The following change fixes it for me, to throw an error if `settings` is null,
but this change needs review and feedback.


diff -r 785ac0d19116 libgui/src/m-editor/file-editor-tab.cc
--- a/libgui/src/m-editor/file-editor-tab.cc    Mon Nov 28 15:28:03 2022
-0500
+++ b/libgui/src/m-editor/file-editor-tab.cc    Mon Nov 28 16:50:28 2022
-0500
@@ -268,8 +268,10 @@ namespace octave
 
     resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
     gui_settings *settings = rmgr.get_settings ();
-    if (settings)
-      notice_settings (settings, true);
+
+    error_unless (settings != nullptr);  // guard against nullptr assignment
+
+    notice_settings (settings, true);
 
     // encoding, not updated with the settings
     m_encoding = settings->value (ed_default_enc.key, "UTF-8").toString ();









    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?63437>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]