From 3375580a2dd15cd218089add38648d9401854aa3 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 6 Apr 2022 10:53:07 -0700 Subject: [PATCH] pbot-vm: fix parsing of quoted text within GDB/MI --- applets/pbot-vm/guest/bin/guest-gdb | 11 +++++++++-- lib/PBot/VERSION.pm | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/applets/pbot-vm/guest/bin/guest-gdb b/applets/pbot-vm/guest/bin/guest-gdb index ff8337b6..c281b3c0 100755 --- a/applets/pbot-vm/guest/bin/guest-gdb +++ b/applets/pbot-vm/guest/bin/guest-gdb @@ -146,7 +146,7 @@ sub gdb_read_result($out) { # convert gdb/mi text to hashtable, converting to JSON first if necessary sub gdbmi_to_hash($text, $makejson = 1) { # convert to JSON first if necessary (gdb/mi is nearly JSON already!) - $text =~ s/([\w-]+)=/"$1":/g if $makejson; + $text =~ s/"(?:[^"\\]|\\.)*"(*SKIP)(*F)|([\w-]+)=/"$1":/g if $makejson; # decode gdb octal escapes # (sometimes \\123, othertimes \123 and I can't be arsed to investigate @@ -161,7 +161,14 @@ sub gdbmi_to_hash($text, $makejson = 1) { $text =~ s/([\x10-\x1f])/sprintf '\\\\x%X', ord $1/ge; # return hashtable decoded from json - return decode_json("{$text}"); + my $result = eval { decode_json("{$text}") }; + + if ($@) { + print "Error parsing GDB/MI: $@ (input: $text)\n"; + exit 1; + } + + return $result; } sub parse_gdbmi_output($line) { diff --git a/lib/PBot/VERSION.pm b/lib/PBot/VERSION.pm index 0ce3dc62..f54d9b1d 100644 --- a/lib/PBot/VERSION.pm +++ b/lib/PBot/VERSION.pm @@ -25,8 +25,8 @@ use PBot::Imports; # These are set by the /misc/update_version script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 4526, - BUILD_DATE => "2022-04-04", + BUILD_REVISION => 4528, + BUILD_DATE => "2022-04-06", }; sub initialize {}