Fix crash if XDG_CACHE_HOME directory is too small or out of space
ClosedPublic

Authored by alexeymin on Nov 7 2018, 9:12 PM.

Details

Summary

Incorrect checking for error return code of posix_fallocate() causes function to think that everything is OK, while it is not, causing crash in some cases.

BUG: 400610
CCBUG: 339829

Test Plan

good test plan provided in https://bugs.kde.org/show_bug.cgi?id=400610 . Works like a charm, tested in KDE Neon dev-ustable

The reason for bug was that return value of posix_fallocate() was assumed to be negative on error, but in fact it is a positive integer. The check was < 0, whi should be != 0. ( http://man7.org/linux/man-pages/man3/posix_fallocate.3.html )

With this fix applied test application does not crash, and the output in console widow is:

No space left on device. Check filesystem free space at your XDG_CACHE_HOME!
The operating system is unable to promise 10547304 bytes for mapped cache, abandoning the cache for crash-safety.
org.kde.kcoreaddons: Failed to establish shared memory mapping, will fallback to private memory -- memory usage will increase

Diff Detail

Repository
R244 KCoreAddons
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
alexeymin created this revision.Nov 7 2018, 9:12 PM
Restricted Application added a project: Frameworks. Β· View Herald TranscriptNov 7 2018, 9:12 PM
Restricted Application added a subscriber: kde-frameworks-devel. Β· View Herald Transcript
alexeymin requested review of this revision.Nov 7 2018, 9:12 PM
alexeymin edited the test plan for this revision. (Show Details)Nov 7 2018, 9:14 PM
alexeymin added a reviewer: dfaure.
alexeymin edited the test plan for this revision. (Show Details)
alexeymin edited the summary of this revision. (Show Details)Nov 7 2018, 9:17 PM
alexeymin added a reviewer: Frameworks.
alexeymin edited the test plan for this revision. (Show Details)Nov 7 2018, 9:23 PM
alexeymin updated this revision to Diff 45077.Nov 7 2018, 9:29 PM
  • Fix typo "in" -> "on"
cfeck added a reviewer: mpyne.Nov 7 2018, 9:30 PM
cfeck added a subscriber: cfeck.

Would a switch be more readable?

Would a switch be more readable?

Did you mean a block with if (result == ENOSPC) { ? Strictly speaking this whole block is not necessary, but it can provide some useful info in console.
Or do you suggest adding switch with all error return codes from http://man7.org/linux/man-pages/man3/posix_fallocate.3.html? πŸ˜•

dfaure accepted this revision.Nov 7 2018, 10:13 PM

switch would require ugly fall-through, I prefer this code.

This revision is now accepted and ready to land.Nov 7 2018, 10:13 PM
This revision was automatically updated to reflect the committed changes.