[CopyJob] Fix crash when copying an already existing dir and pressing "Skip"
ClosedPublic

Authored by ahmadsamir on Sep 3 2019, 4:22 PM.

Details

Summary

In copyNextFile() if all files have been skipped QList::erase() will
return end() iterator, accessing the element it denotes will cause
a segmentation fault. Make sure the iterator is valid if it's changed
inside the while loop, if we're going to use it before control reaches
the loop condition.

Add a unit test.

BUG: 408350
FIXED-IN: 5.62.0

Test Plan

kioclient5 copy SOME_DIR_WITH_FILES DEST
kioclient5 copy --interactive SOME_DIR_WITH_FILES DEST

  • In the "folder already exists" dialog enable "Apply to all" then hit "Skip"
  • Without the patch you'd get a segmentation fault, with the patch the copy should finish as expected

All unit tests passed (except kiocore-kacltest, but that's unrelated).

Diff Detail

Repository
R241 KIO
Branch
ahmad/copyjob (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 16156
Build 16174: arc lint + arc unit
ahmadsamir created this revision.Sep 3 2019, 4:22 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptSep 3 2019, 4:22 PM
ahmadsamir requested review of this revision.Sep 3 2019, 4:22 PM
dfaure requested changes to this revision.Sep 5 2019, 8:43 AM

Thanks for the fix!

Do you feel like writing a unittest for it?
JobTest::chmodFileError shows how to use PredefinedAnswerJobUiDelegate to simulate the user pressing "Skip" in the dialog.
Write the test without your fix applied, so that you are sure it triggers the crash, before re-applying the fix.

src/core/copyjob.cpp
1640

This comment only needs to be in the unittest, not in the code.

If every bugfix leads to two lines of comments, the code becomes unreadable.

This revision now requires changes to proceed.Sep 5 2019, 8:43 AM
ahmadsamir updated this revision to Diff 65486.Sep 5 2019, 10:07 PM
ahmadsamir retitled this revision from [CopyJob] Fix crash when copying all files is skipped for an already existing dir to [CopyJob] Fix crash when copying an already existing dir and pressing "Skip".
ahmadsamir edited the summary of this revision. (Show Details)
ahmadsamir edited the test plan for this revision. (Show Details)

Add a unit test
Move the comments to the unit test

ahmadsamir marked an inline comment as done.Sep 5 2019, 10:09 PM

Thanks for the fix!

Do you feel like writing a unittest for it?
JobTest::chmodFileError shows how to use PredefinedAnswerJobUiDelegate to simulate the user pressing "Skip" in the dialog.
Write the test without your fix applied, so that you are sure it triggers the crash, before re-applying the fix.

That's exactly what I did.

Thanks.

src/core/copyjob.cpp
1640

OK.

dfaure accepted this revision.Sep 6 2019, 8:22 AM

Great job, thanks!
Do you have a developer account, or shall I commit this?

This revision is now accepted and ready to land.Sep 6 2019, 8:22 AM
ahmadsamir marked an inline comment as done.Sep 6 2019, 1:10 PM

Please commit it.

Thanks.

dfaure closed this revision.Sep 6 2019, 2:07 PM