diff options
author | Bernd Weimer <bernd.weimer@pelagicore.com> | 2020-01-14 12:30:55 +0100 |
---|---|---|
committer | Bernd Weimer <bernd.weimer@pelagicore.com> | 2020-01-14 16:59:55 +0100 |
commit | 533724b238ec6da240e01f7e5bff594f5b74f144 (patch) | |
tree | 03fd637968b50786f623b1e05fc0b83f1b35cb0d | |
parent | 43fa48acc7d511760ee579ef51b09ff746e3a33c (diff) |
Update demangle buffer
Function __cxa_demangle will reallocate the output buffer, if it is
too short. To avoid a potential dangling buffer (pointer), it is
always updated. Increased the initial buffer size, as well.
Cherry-picked from 5.13: 0c69e08
Change-Id: I11f331e51fa28f940d4843740c0b0137d8d47dc4
Reviewed-by: Robert Griebl <robert.griebl@qt.io>
-rw-r--r-- | src/common-lib/crashhandler.cpp | 10 | ||||
-rw-r--r-- | tests/qml/crash/apps/tld.test.crash/terminator2/qmlterminator2.cpp | 7 | ||||
-rw-r--r-- | tests/qml/crash/tst_crash.qml | 4 |
3 files changed, 13 insertions, 8 deletions
diff --git a/src/common-lib/crashhandler.cpp b/src/common-lib/crashhandler.cpp index 01fa1636..6efbcf9a 100644 --- a/src/common-lib/crashhandler.cpp +++ b/src/common-lib/crashhandler.cpp @@ -146,7 +146,7 @@ static void initBacktrace() getOutputInformation(&useAnsiColor, nullptr, nullptr); - demangleBufferSize = 512; + demangleBufferSize = 768; demangleBuffer = static_cast<char *>(malloc(demangleBufferSize)); UnixSignalHandler::instance()->install(UnixSignalHandler::RawSignalHandler, @@ -172,7 +172,7 @@ static void initBacktrace() const char *typeName = type->name(); if (typeName) { int status; - abi::__cxa_demangle(typeName, demangleBuffer, &demangleBufferSize, &status); + demangleBuffer = abi::__cxa_demangle(typeName, demangleBuffer, &demangleBufferSize, &status); if (status == 0 && *demangleBuffer) { typeName = demangleBuffer; } @@ -272,7 +272,7 @@ static void printCrashInfo(PrintDestination dest, const char *why, int stackFram int level = static_cast<btData *>(data)->level; if (symname) { int status; - abi::__cxa_demangle(symname, demangleBuffer, &demangleBufferSize, &status); + demangleBuffer = abi::__cxa_demangle(symname, demangleBuffer, &demangleBufferSize, &status); if (status == 0 && *demangleBuffer) printBacktraceLine(level, demangleBuffer, pc); @@ -287,7 +287,7 @@ static void printCrashInfo(PrintDestination dest, const char *why, int stackFram const char *function) -> int { if (function) { int status; - abi::__cxa_demangle(function, demangleBuffer, &demangleBufferSize, &status); + demangleBuffer = abi::__cxa_demangle(function, demangleBuffer, &demangleBufferSize, &status); printBacktraceLine(static_cast<btData *>(data)->level, (status == 0 && *demangleBuffer) ? demangleBuffer : function, @@ -345,7 +345,7 @@ static void printCrashInfo(PrintDestination dest, const char *why, int stackFram *end = 0; int status; - abi::__cxa_demangle(function, demangleBuffer, &demangleBufferSize, &status); + demangleBuffer = abi::__cxa_demangle(function, demangleBuffer, &demangleBufferSize, &status); if (status == 0 && *demangleBuffer) { printMsg(" %3d: %s [+%s]", i, demangleBuffer, offset + 1); diff --git a/tests/qml/crash/apps/tld.test.crash/terminator2/qmlterminator2.cpp b/tests/qml/crash/apps/tld.test.crash/terminator2/qmlterminator2.cpp index 64210f63..05e73934 100644 --- a/tests/qml/crash/apps/tld.test.crash/terminator2/qmlterminator2.cpp +++ b/tests/qml/crash/apps/tld.test.crash/terminator2/qmlterminator2.cpp @@ -47,6 +47,11 @@ void TerminatorPlugin::registerTypes(const char *uri) } +static void abortWithVeryLongSymbolNameOnTheStack800CharactersLong_CallMeIshmaelSomeYearsAgoNeverMindHowLongPreciselyHavingLittleOrNoMoneyInMyPurseAndNothingParticularToInterestMeOnShoreIThoughIWouldSailAboutALittlAndSeeTheWateryPartOfTheWorldItIsAWayIHaveOfDrivingOffTheSpleenAndRegulatingTheCirculationWhenenverIFindMyselfGrowingGrimAboutTheMouthWheneverItIsADampDrizzlyNovemberInMySoulWheneverIFindMyselfInvoluntarilyPausingBeforeCoffinWarehousesAndBringingUpTheRearOfEveryFuneralIMeetAndEspeciallyWheneverMyHyposGetSuchAnUpperHandOfMeThatItRequiresAStrongMoralPrincipleToPreventMeFromDeliberatelySteppingIntoTheStreetAndMethodicallyKnockingPeoplesHatsOffThenIAccountItHighTimeToGetToSeaAsSoonAsICanThisIsMySubstituteForPistolAndBallWithAPhilosophicalFlourishCatoThrowsHimselfUponHisSwordIQuietlyTakeToTheShip() +{ + ::abort(); +} + void Terminator::accessIllegalMemory() const { *(int*)1 = 42; @@ -76,7 +81,7 @@ void Terminator::divideByZero() const void Terminator::abort() const { - ::abort(); + abortWithVeryLongSymbolNameOnTheStack800CharactersLong_CallMeIshmaelSomeYearsAgoNeverMindHowLongPreciselyHavingLittleOrNoMoneyInMyPurseAndNothingParticularToInterestMeOnShoreIThoughIWouldSailAboutALittlAndSeeTheWateryPartOfTheWorldItIsAWayIHaveOfDrivingOffTheSpleenAndRegulatingTheCirculationWhenenverIFindMyselfGrowingGrimAboutTheMouthWheneverItIsADampDrizzlyNovemberInMySoulWheneverIFindMyselfInvoluntarilyPausingBeforeCoffinWarehousesAndBringingUpTheRearOfEveryFuneralIMeetAndEspeciallyWheneverMyHyposGetSuchAnUpperHandOfMeThatItRequiresAStrongMoralPrincipleToPreventMeFromDeliberatelySteppingIntoTheStreetAndMethodicallyKnockingPeoplesHatsOffThenIAccountItHighTimeToGetToSeaAsSoonAsICanThisIsMySubstituteForPistolAndBallWithAPhilosophicalFlourishCatoThrowsHimselfUponHisSwordIQuietlyTakeToTheShip(); } void Terminator::raise(int sig) const diff --git a/tests/qml/crash/tst_crash.qml b/tests/qml/crash/tst_crash.qml index 89ae9a9b..8360652b 100644 --- a/tests/qml/crash/tst_crash.qml +++ b/tests/qml/crash/tst_crash.qml @@ -66,10 +66,10 @@ TestCase { return [ { tag: "gracefully" }, { tag: "illegalMemory" }, { tag: "illegalMemoryInThread" }, - { tag: "unhandledException" } ]; + { tag: "unhandledException" }, + { tag: "abort" } ]; //{ tag: "stackOverflow" }, //{ tag: "divideByZero" }, - //{ tag: "abort" }, //{ tag: "raise" } ]; } |