Commit 45485d9e authored by Marc Mutz's avatar Marc Mutz Committed by Kai Koehne
Browse files

Fix undefined behavior in QLoggingRegistry::defaultCategoryFilter()


Report by asan:

  READ of size 2 at 0x00000041dd40 thread T0
    #0 0x2af097b84da6 in QLoggingRegistry::defaultCategoryFilter(QLoggingCategory*) (lib/libQt5Core.so.5+0x566da6)
    #1 0x2af097b8387b in QLoggingRegistry::registerCategory(QLoggingCategory*, QtMsgType) (lib/libQt5Core.so.5+0x56587b)
    #2 0x4067f7 in tst_QLogging::QLoggingCategory_categoryName() tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp:238
    <snip>

  0x00000041dd41 is located 0 bytes to the right of global variable '*.LC115' defined in 'tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp' (0x41dd40) of size 1
    '*.LC115' is ascii string ''

At face value, memcmp("", "qt", 2) should not return 0, but since
the code invokes undefined behavior, the compiler can do whatever
it wants, including returning 0 here, further proving the fact
that there are *no* benign cases of undefined behavior.

Change-Id: I0c38622c47d1dcea450ea549370be1673b47b18d
Reviewed-by: default avatarKai Koehne <kai.koehne@theqtcompany.com>
Reviewed-by: default avatarOlivier Goffart <ogoffart@woboq.com>
Showing with 5 additions and 3 deletions
...@@ -398,9 +398,11 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat) ...@@ -398,9 +398,11 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
// hard-wired implementation of // hard-wired implementation of
// qt.*.debug=false // qt.*.debug=false
// qt.debug=false // qt.debug=false
char c; if (const char *categoryName = cat->categoryName()) {
if (!memcmp(cat->categoryName(), "qt", 2) && (!(c = cat->categoryName()[2]) || c == '.')) // == "qt" or startsWith("qt.")
debug = false; if (strcmp(categoryName, "qt") == 0 || strncmp(categoryName, "qt.", 3) == 0)
debug = false;
}
QString categoryName = QLatin1String(cat->categoryName()); QString categoryName = QLatin1String(cat->categoryName());
foreach (const QLoggingRule &item, reg->rules) { foreach (const QLoggingRule &item, reg->rules) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment