Fix segfault on no restart args
ClosedPublic

Authored by jpalecek on May 17 2020, 5:52 PM.

Details

Summary

When an application is crashing through KCrash, but has no restart
argument list, KCrash itself crashes because s_autoRestartCommandLine
is null (when it wants to print the command line to stdout). This
patch fixes that by making sure s_autoRestartCommandLine is always
non-null.

Depends on D29810
Signed-off-by: Jiří Paleček <jpalecek@web.de>

Diff Detail

Repository
R285 KCrash
Branch
for-upstream
Lint
Lint OK
Unit
No Unit Test Coverage
jpalecek created this revision.May 17 2020, 5:52 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptMay 17 2020, 5:52 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
jpalecek requested review of this revision.May 17 2020, 5:52 PM
jpalecek updated this revision to Diff 83138.May 24 2020, 1:27 AM
jpalecek edited the summary of this revision. (Show Details)

Edited the commit msg, also prune the dependencies I want to abandon

dfaure requested changes to this revision.May 27 2020, 9:39 PM

I'm a bit confused by the bug this is fixing. Surely this doesn't happen to all cases of crashes without autorestart enabled??

Also, it sounds like a null check might be enough.

src/kcrash.cpp
107

Should this become 1 then? Otherwise the for loop won't delete that new new char*[1]

272

insert(0) reads like prepend, but args is empty anyway, why not just use append?

275

We use { ... } braces also around single-line statements in KF5.

Can you do the same for the if above too?

This revision now requires changes to proceed.May 27 2020, 9:39 PM

I'm a bit confused by the bug this is fixing. Surely this doesn't happen to all cases of crashes without autorestart enabled??

Also, it sounds like a null check might be enough.

No. It is a crash where s_autoRestartCommandLine was null. The actual crash happened in the logging code, but it is also used in startProcess and I think going for non-null s_autoRestartCommandLine is actually easier than faffing with null pointer checks and special casing in the signal handler code. Even with no restart arguments, you still need argv to hold the executable name to restart, so why not maintain it uniformly? It only costs a few bytes of heap.

src/kcrash.cpp
107

No. The invariant is that s_autoRestartArgc is the number of arguments, not counting the last null. The new char*[1] is deleted after the loop.

272

Well I was thinking about resize(), then found there wasn't any. However, if we want to be clear, maybe args = { QString() } would be the best?

(In reality, the effect should be args = { filePath }, but that comes with the next line.)

Can you explain how to trigger this crash in the first place? Which application triggers it?

src/kcrash.cpp
272

I like your suggestion.

jpalecek updated this revision to Diff 83214.Jun 4 2020, 8:03 PM

Polished the style as requested

dfaure added a comment.Jun 6 2020, 1:12 PM

This commit seems to include the changes requested in the other review...

jpalecek updated this revision to Diff 83232.Jun 6 2020, 1:43 PM

Remove contamination from another patch made by the last upload

dfaure added a comment.Jun 6 2020, 2:11 PM

This question is still without an answer: "Can you explain how to trigger this crash in the first place? Which application triggers it?"

This question is still without an answer: "Can you explain how to trigger this crash in the first place? Which application triggers it?"

That's because I don't know in which binary I have seen it. The patch itself is more than 6 months old and I don't remember what I was doing then. Not that I would care that much, IMHO the code should be resilient enough not to crash when someone does weird things with QApplication. After all, if apps had no bugs, there wouldn't be need for kcrash in the first place.

The comment on one line says that tst_QX11Info::startupId does QApplication app(argc, nullptr) and this would certainly trigger it (should the following execution crash). That comment convinced me this usage is at least sort-of valid and so I wrote the patch.

dfaure accepted this revision.Jun 7 2020, 9:17 AM
This revision is now accepted and ready to land.Jun 7 2020, 9:17 AM
dfaure closed this revision.Jun 7 2020, 9:22 AM