Skip to content

Instantly share code, notes, and snippets.

@termie
Last active July 6, 2025 01:05
Show Gist options
  • Save termie/f865035095bc41c4f38cb794bcf593f1 to your computer and use it in GitHub Desktop.
Save termie/f865035095bc41c4f38cb794bcf593f1 to your computer and use it in GitHub Desktop.
mudlet trigger match error

triggering regex: [[^(?<front>(?:\([^)]+\) |\s+)+)(?<name>[^\[\n]+)(?<label>\[.+\])?]]

for lines like:

( 2) (Humming) the ancient amulet of the grandmaster
     sulfurous ashes
     Dr. Sheaf's Miracle Cure-All Bag [typhus] 
     a plain crate [misc] 

this one doesn't though [[^Level (?<level>\d+)\((?<sublevel>\d+)\)? (?<race>.*) (?<class>\w+)\s+Exp\/TNL.*$]]

for this line:

Level 51(343) Drow Black Circle Initiate    Exp/TNL:     461851/317   .[me] 

both are temp triggers made this way

    local ref = mudlet.tempRegexTrigger(
      patt,
      function ()
        local cur = mudlet.getCurrentLine()
        --self:debugf("Triggering %s with %s", name, cur)
        local submatches = {rex.match(cur, patt)}
        --local submatches = {}
        --self:debugf("Matches: %s", table.concat(matches, ", "))
        table.insert(submatches, 1, cur)
        func(self, pl.unpack(submatches))
      end
    )

where rex is local rex = require("rex_pcre") swapping the two submatches lines (so the r ex match never gets called) doesn't change the behavior, I don't think it gets to it

=================================================================
==103122==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7c4ca1d1ad5f at pc 0x55826387dac7 bp 0x7ffd5e70dc30 sp 0x7ffd5e70dc20
READ of size 1 at 0x7c4ca1d1ad5f thread T0
#0 0x55826387dac6 in lengthHelperPointer<char> /usr/include/qt6/QtCore/qbytearrayview.h:77
#1 0x558263896495 in QByteArrayView::QByteArrayView<char const*, true>(char const* const&) /usr/include/qt6/QtCore/qbytearrayview.h:161
#2 0x558263974a2c in QString::QString(char const*) /usr/include/qt6/QtCore/qstring.h:924
#3 0x5582649fa694 in TTrigger::processRegexMatch(char const*, QString const&, int, int, QSharedPointer<real_pcre8_or_16> const&, int, int, int*) /home/termie/p/mudlet/src/TTrigger.cpp:380
#4 0x5582649f86dc in TTrigger::match_perl(char*, QString const&, int, int) /home/termie/p/mudlet/src/TTrigger.cpp:316
#5 0x558264a047ce in TTrigger::match(char*, QString const&, int, int) /home/termie/p/mudlet/src/TTrigger.cpp:1026
#6 0x5582648c91af in TriggerUnit::processDataStream(QString const&, int) /home/termie/p/mudlet/src/TriggerUnit.cpp:250
#7 0x558263ff4f5f in Host::incomingStreamProcessor(QString const&, int) /home/termie/p/mudlet/src/Host.cpp:1653
#8 0x558264741bb1 in TMainConsole::runTriggers(int) /home/termie/p/mudlet/src/TMainConsole.cpp:1206
#9 0x5582643a1bad in TBuffer::translateToPlainText(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool) /home/termie/p/mudlet/src/TBuffer.cpp:853
#10 0x558264740b72 in TMainConsole::printOnDisplay(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool) /home/termie/p/mudlet/src/TMainConsole.cpp:1150
#11 0x5582639659be in cTelnet::postData() /home/termie/p/mudlet/src/ctelnet.cpp:3612
#12 0x5582639651f0 in cTelnet::gotRest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) /home/termie/p/mudlet/src/ctelnet.cpp:3558
#13 0x55826396ac4c in cTelnet::processSocketData(char*, int, bool) /home/termie/p/mudlet/src/ctelnet.cpp:4070
#14 0x558263968c16 in cTelnet::slot_socketReadyToBeRead() /home/termie/p/mudlet/src/ctelnet.cpp:3872
#15 0x5582639a5f08 in QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, void (cTelnet::*)()>::call(void (cTelnet::*)(), cTelnet*, void**)::{lambda()#1}::operator()() const /usr/include/qt6/QtCore/qobjectdefs_impl.h:127
#16 0x5582639ac3fd in void QtPrivate::FunctorCallBase::call_internal<void, QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, void (cTelnet::*)()>::call(void (cTelnet::*)(), cTelnet*, void**)::{lambda()#1}>(void**, QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, void (cTelnet::*)()>::call(void (cTelnet::*)(), cTelnet*, void**)::{lambda()#1}&&) (/home/termie/p/mudlet/build-cmake/src/mudlet+0xc463fd) (BuildId: dcd7e5c1e3864558b4cad75cb79725ef4e09950f)
#17 0x5582639a60d8 in QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, void (cTelnet::*)()>::call(void (cTelnet::*)(), cTelnet*, void**) /usr/include/qt6/QtCore/qobjectdefs_impl.h:126
#18 0x55826399f569 in void QtPrivate::FunctionPointer<void (cTelnet::*)()>::call<QtPrivate::List<>, void>(void (cTelnet::*)(), cTelnet*, void**) (/home/termie/p/mudlet/build-cmake/src/mudlet+0xc39569) (BuildId: dcd7e5c1e3864558b4cad75cb79725ef4e09950f)
#19 0x558263998bf7 in QtPrivate::QCallableObject<void (cTelnet::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) /usr/include/qt6/QtCore/qobjectdefs_impl.h:545
#20 0x7feca6bd37ee (/usr/lib/libQt6Core.so.6+0x1d37ee) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#21 0x7feca6bd3b89 (/usr/lib/libQt6Core.so.6+0x1d3b89) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#22 0x7feca72cf1e7 (/usr/lib/libQt6Network.so.6+0xb71e7) (BuildId: 7335d1764fc09bb498d0a4514947ffb775e93e6a)
#23 0x7feca72db9c1 (/usr/lib/libQt6Network.so.6+0xc39c1) (BuildId: 7335d1764fc09bb498d0a4514947ffb775e93e6a)
#24 0x7feca6301c6f in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/usr/lib/libQt6Widgets.so.6+0x101c6f) (BuildId: f7f0b0fb1a3a089a2d8f3747ddd2913c22f2b916)
#25 0x7feca6b68117 in QCoreApplication::notifyInternal2(QObject*, QEvent*) (/usr/lib/libQt6Core.so.6+0x168117) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#26 0x7feca6e3f9f1 (/usr/lib/libQt6Core.so.6+0x43f9f1) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#27 0x7feca48a987c (/usr/lib/libglib-2.0.so.0+0x5e87c) (BuildId: cbfaf9b4447ee7fe27c3afece9eb755e110212af)
#28 0x7feca48aacd6 (/usr/lib/libglib-2.0.so.0+0x5fcd6) (BuildId: cbfaf9b4447ee7fe27c3afece9eb755e110212af)
#29 0x7feca48aaee4 in g_main_context_iteration (/usr/lib/libglib-2.0.so.0+0x5fee4) (BuildId: cbfaf9b4447ee7fe27c3afece9eb755e110212af)
#30 0x7feca6e3c5e1 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (/usr/lib/libQt6Core.so.6+0x43c5e1) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#31 0x7feca6b744b5 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (/usr/lib/libQt6Core.so.6+0x1744b5) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#32 0x7feca6b6c7c0 in QCoreApplication::exec() (/usr/lib/libQt6Core.so.6+0x16c7c0) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#33 0x5582641337f8 in main /home/termie/p/mudlet/src/main.cpp:748
#34 0x7feca52376b4 (/usr/lib/libc.so.6+0x276b4) (BuildId: 468e3585c794491a48ea75fceb9e4d6b1464fc35)
#35 0x7feca5237768 in __libc_start_main (/usr/lib/libc.so.6+0x27768) (BuildId: 468e3585c794491a48ea75fceb9e4d6b1464fc35)
#36 0x55826385fca4 in _start (/home/termie/p/mudlet/build-cmake/src/mudlet+0xaf9ca4) (BuildId: dcd7e5c1e3864558b4cad75cb79725ef4e09950f)
0x7c4ca1d1ad5f is located 1 bytes before 54-byte region [0x7c4ca1d1ad60,0x7c4ca1d1ad96)
allocated by thread T0 here:
#0 0x7feca7720e15 in malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:67
#1 0x7feca767cc6a in strndup /usr/src/debug/gcc/gcc/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:450
#2 0x5582648c904a in TriggerUnit::processDataStream(QString const&, int) /home/termie/p/mudlet/src/TriggerUnit.cpp:246
#3 0x558263ff4f5f in Host::incomingStreamProcessor(QString const&, int) /home/termie/p/mudlet/src/Host.cpp:1653
#4 0x558264741bb1 in TMainConsole::runTriggers(int) /home/termie/p/mudlet/src/TMainConsole.cpp:1206
#5 0x5582643a1bad in TBuffer::translateToPlainText(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool) /home/termie/p/mudlet/src/TBuffer.cpp:853
#6 0x558264740b72 in TMainConsole::printOnDisplay(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, bool) /home/termie/p/mudlet/src/TMainConsole.cpp:1150
#7 0x5582639659be in cTelnet::postData() /home/termie/p/mudlet/src/ctelnet.cpp:3612
#8 0x5582639651f0 in cTelnet::gotRest(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) /home/termie/p/mudlet/src/ctelnet.cpp:3558
#9 0x55826396ac4c in cTelnet::processSocketData(char*, int, bool) /home/termie/p/mudlet/src/ctelnet.cpp:4070
#10 0x558263968c16 in cTelnet::slot_socketReadyToBeRead() /home/termie/p/mudlet/src/ctelnet.cpp:3872
#11 0x5582639a5f08 in QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, void (cTelnet::*)()>::call(void (cTelnet::*)(), cTelnet*, void**)::{lambda()#1}::operator()() const /usr/include/qt6/QtCore/qobjectdefs_impl.h:127
#12 0x5582639ac3fd in void QtPrivate::FunctorCallBase::call_internal<void, QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, void (cTelnet::*)()>::call(void (cTelnet::*)(), cTelnet*, void**)::{lambda()#1}>(void**, QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, void (cTelnet::*)()>::call(void (cTelnet::*)(), cTelnet*, void**)::{lambda()#1}&&) (/home/termie/p/mudlet/build-cmake/src/mudlet+0xc463fd) (BuildId: dcd7e5c1e3864558b4cad75cb79725ef4e09950f)
#13 0x5582639a60d8 in QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, void (cTelnet::*)()>::call(void (cTelnet::*)(), cTelnet*, void**) /usr/include/qt6/QtCore/qobjectdefs_impl.h:126
#14 0x55826399f569 in void QtPrivate::FunctionPointer<void (cTelnet::*)()>::call<QtPrivate::List<>, void>(void (cTelnet::*)(), cTelnet*, void**) (/home/termie/p/mudlet/build-cmake/src/mudlet+0xc39569) (BuildId: dcd7e5c1e3864558b4cad75cb79725ef4e09950f)
#15 0x558263998bf7 in QtPrivate::QCallableObject<void (cTelnet::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) /usr/include/qt6/QtCore/qobjectdefs_impl.h:545
#16 0x7feca6bd37ee (/usr/lib/libQt6Core.so.6+0x1d37ee) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#17 0x7feca6bd3b89 (/usr/lib/libQt6Core.so.6+0x1d3b89) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#18 0x7feca72cf1e7 (/usr/lib/libQt6Network.so.6+0xb71e7) (BuildId: 7335d1764fc09bb498d0a4514947ffb775e93e6a)
#19 0x7feca72db9c1 (/usr/lib/libQt6Network.so.6+0xc39c1) (BuildId: 7335d1764fc09bb498d0a4514947ffb775e93e6a)
#20 0x7feca6301c6f in QApplicationPrivate::notify_helper(QObject*, QEvent*) (/usr/lib/libQt6Widgets.so.6+0x101c6f) (BuildId: f7f0b0fb1a3a089a2d8f3747ddd2913c22f2b916)
#21 0x7feca6b68117 in QCoreApplication::notifyInternal2(QObject*, QEvent*) (/usr/lib/libQt6Core.so.6+0x168117) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#22 0x7feca6e3f9f1 (/usr/lib/libQt6Core.so.6+0x43f9f1) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#23 0x7feca48a987c (/usr/lib/libglib-2.0.so.0+0x5e87c) (BuildId: cbfaf9b4447ee7fe27c3afece9eb755e110212af)
#24 0x7feca48aacd6 (/usr/lib/libglib-2.0.so.0+0x5fcd6) (BuildId: cbfaf9b4447ee7fe27c3afece9eb755e110212af)
#25 0x7feca48aaee4 in g_main_context_iteration (/usr/lib/libglib-2.0.so.0+0x5fee4) (BuildId: cbfaf9b4447ee7fe27c3afece9eb755e110212af)
#26 0x7feca6e3c5e1 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (/usr/lib/libQt6Core.so.6+0x43c5e1) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#27 0x7feca6b744b5 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (/usr/lib/libQt6Core.so.6+0x1744b5) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#28 0x7feca6b6c7c0 in QCoreApplication::exec() (/usr/lib/libQt6Core.so.6+0x16c7c0) (BuildId: 87fda2aacc2207cf15c167c45b3dab4a5675c67b)
#29 0x5582641337f8 in main /home/termie/p/mudlet/src/main.cpp:748
SUMMARY: AddressSanitizer: heap-buffer-overflow /usr/include/qt6/QtCore/qbytearrayview.h:77 in lengthHelperPointer<char>
Shadow bytes around the buggy address:
0x7c4ca1d1aa80: 00 00 00 00 fa fa fa fa fd fd fd fd fd fd fd fd
0x7c4ca1d1ab00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x7c4ca1d1ab80: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
0x7c4ca1d1ac00: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
0x7c4ca1d1ac80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x7c4ca1d1ad00: fd fd fd fd fd fd fd fd fa fa fa[fa]00 00 00 00
0x7c4ca1d1ad80: 00 00 06 fa fa fa fa fa fd fd fd fd fd fd fd fd
0x7c4ca1d1ae00: fa fa fa fa fd fd fd fd fd fd fd fd fa fa fa fa
0x7c4ca1d1ae80: fa fa fa fa fa fa fa fa fa fa fa fa fd fd fd fd
0x7c4ca1d1af00: fd fd fd fd fa fa fa fa fa fa fa fa fa fa fa fa
0x7c4ca1d1af80: fa fa fa fa fd fd fd fd fd fd fd fd fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==103122==ABORTING
crashes on
(Magical) everything withers [poison]
(Magical) everything floats [orbit]
(Magical) everything changes [transmog]
(Magical) Some raging flames skin bag
(Empty) a legendary leggings engraved cube
everything matters [mainbag]
everything happens [miscbag]
does not crash on
everything matters [mainbag]
everything happens [miscbag]
if (namecount > 0) {
// Based on snippet https://github.com/vmg/pcre/blob/master/pcredemo.c#L216
// Retrieves char table end entry size and extracts name of group and captures from
pcre_fullinfo(re.data(), nullptr, PCRE_INFO_NAMETABLE, &tabptr);
pcre_fullinfo(re.data(), nullptr, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
for (i = 0; i < namecount; ++i) {
const int n = (tabptr[0] << 8) | tabptr[1];
auto name = QString::fromUtf8(&tabptr[2]).trimmed(); //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-pro-bounds-constant-array-index)
auto* substring_start = haystackC + ovector[2*n]; //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-pro-bounds-constant-array-index)
auto substring_length = ovector[2*n+1] - ovector[2*n]; //NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
THISLINE auto utf16_pos = haystack.indexOf(QString(substring_start));
auto capture = QString::fromUtf8(substring_start, substring_length);
nameGroups << qMakePair(name, capture);
tabptr += name_entry_size;
namePositions.insert(name, qMakePair(utf16_pos + posOffset, substring_length));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment