From ee311f5ca75918e89dacade1de3f8cca40ea6684 Mon Sep 17 00:00:00 2001 From: KerfuffleV2 Date: Fri, 3 Nov 2023 05:20:06 -0600 Subject: [PATCH 1/2] Allow common process_escapes to handle \x sequences --- common/common.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/common.cpp b/common/common.cpp index 20cc4a081b222..9194c701e5f59 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -90,6 +90,19 @@ void process_escapes(std::string& input) { case '\'': input[output_idx++] = '\''; break; case '\"': input[output_idx++] = '\"'; break; case '\\': input[output_idx++] = '\\'; break; + case 'x': + // Handle \x12, etc + if (input_idx + 2 < input_len && input[input_idx + 1] != 0) { + const char x[3] = { input[input_idx + 1], input[input_idx + 2], 0 }; + char *err_p = nullptr; + const long val = std::strtol(x, &err_p, 16); + if (*err_p == 0) { + input_idx += 2; + input[output_idx++] = char(val); + break; + } + // Intentionally fall through to default. + } default: input[output_idx++] = '\\'; input[output_idx++] = input[input_idx]; break; } From 05bbadf3a52fa0b06a225cebd1a8ca6ca5fffdbb Mon Sep 17 00:00:00 2001 From: KerfuffleV2 Date: Fri, 3 Nov 2023 16:33:39 -0600 Subject: [PATCH 2/2] Fix edge case when second hex digit is NUL --- common/common.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index 9194c701e5f59..37e3ace8ac5d9 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -92,11 +92,11 @@ void process_escapes(std::string& input) { case '\\': input[output_idx++] = '\\'; break; case 'x': // Handle \x12, etc - if (input_idx + 2 < input_len && input[input_idx + 1] != 0) { + if (input_idx + 2 < input_len) { const char x[3] = { input[input_idx + 1], input[input_idx + 2], 0 }; char *err_p = nullptr; const long val = std::strtol(x, &err_p, 16); - if (*err_p == 0) { + if (err_p == x + 2) { input_idx += 2; input[output_idx++] = char(val); break;