Don't crash when a log message has no category (fixes #251) - #255
Open
munzzyy wants to merge 1 commit into
Open
Conversation
Logger::messageOutput() does strcmp(context.category, "default") to decide whether a line belongs in the in-app log viewer. context.category is a raw const char* and isn't always set: Qt's qErrnoWarning() builds a default-constructed QMessageLogContext and leaves category null, and that context reaches the installed handler unchanged. The handler is installed process-wide in both the GUI and the CLI, so it sees Qt's internal warnings too. That's the crash in issue flipperdevices#251. The attached coredump has strcmp called from Logger::messageOutput at logger.cpp:80 with context = {version = 2, line = 0, file = 0x0, function = 0x0, category = 0x0}, reached via qErrnoWarning("inotify_add_watch(%ls) failed:") from QInotifyFileSystemWatcherEngine::addPaths while KDE's directory watcher was walking the file dialog. Treat a null category the same as "default", which is what Qt's own isDefaultCategory() does. Filtering behaviour is unchanged. Signed-off-by: Cole Munz <colemunz@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #251.
Logger::messageOutput()decides whether a line belongs in the in-app log viewer with:context.categoryis a rawconst char*and isn't always set. Qt'sqErrnoWarning()builds a default-constructedQMessageLogContextand leavescategorynull, and that context reaches the installed handler unchanged —qt_message_print()forwards it as-is. Since this handler is installed process-wide (bothapplication.cppandcli.cppcallqInstallMessageHandler), it also receives Qt's own internal warnings, so a null category is reachable.That's the crash in #251. From the
qflipper_gdb.txtattached to that issue:category = 0x0right there in the frame, and the caller isqErrnoWarningfromQInotifyFileSystemWatcherEngine::addPaths— KDE's directory watcher hitting the inotify watch limit while the firmware file dialog walks directories. That matches the reporter's "crashes when browsing files" exactly.The fix treats a null category the same as
"default", which is what Qt does internally for this same check (isDefaultCategory()inqlogging.cppis!category || strcmp(category, "default") == 0). Filtering behaviour doesn't change: uncategorised messages were already kept out of the log viewer, and they're still written to stderr and the log file a few lines above this check.I couldn't build qFlipper here, so I verified this from the source and the coredump rather than by running it. To confirm on a machine that can: reproduce #251 (browse for a firmware file on a KDE system near its
fs.inotify.max_user_watcheslimit) and check that it no longer crashes and the message still lands in the saved log.