Folder::showSyncResultPopup: Fix undefined behavior when there is no errors
authorOlivier Goffart <ogoffart@woboq.com>
Thu, 16 Mar 2017 15:30:28 +0000 (16:30 +0100)
committerOlivier Goffart <olivier@woboq.com>
Mon, 20 Mar 2017 10:53:13 +0000 (11:53 +0100)
When there is no errors  _syncResult.firstItemError() is NULL, and accessing
it's _file member is an undefined behavior. (Thankfully, createGuiLog did not
use the string when the count was 0, but we are not supposed to create
null references.

Found with the UB sanitizer:

src/gui/folder.cpp:348:49: runtime error: member access within null pointer of type 'OCC::SyncFileItem'
src/gui/folder.cpp:348:19: runtime error: reference binding to null pointer of type 'const QString'

src/gui/folder.cpp

index 18d2f2b12f7e8d386f037dfe9f896a30caa4d05f..d20215a0ed3b9c82c172271eb60794e789b439e8 100644 (file)
@@ -345,7 +345,9 @@ void Folder::showSyncResultPopup()
     if( _syncResult.firstConflictItem() ) {
         createGuiLog( _syncResult.firstConflictItem()->_file, LogStatusConflict, _syncResult.numConflictItems() );
     }
-    createGuiLog( _syncResult.firstItemError()->_file, LogStatusError, _syncResult.numErrorItems() );
+    if (int errorCount = _syncResult.numErrorItems()) {
+        createGuiLog( _syncResult.firstItemError()->_file, LogStatusError, errorCount );
+    }
 
     qDebug() << "OO folder slotSyncFinished: result: " << int(_syncResult.status());
 }