From 9941f620c442f0996d7889d948b781304e5fb0f2 Mon Sep 17 00:00:00 2001 From: Brian McGee Date: Mon, 31 Jul 2023 18:40:45 +0100 Subject: [PATCH] base64Decode: clearer error message when an invalid character is detected Output the offending string in its entirety to provide context. Closes #8479 (cherry picked from commit dc3ccf02bfd4d359228b54f5c24ae2b6caf6428e) --- src/libutil/util.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 698e181a1..174e7ce8f 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -260,8 +260,9 @@ std::string base64Decode(std::string_view s) if (c == '\n') continue; char digit = base64DecodeChars[(unsigned char) c]; - if (digit == npos) - throw Error("invalid character in Base64 string: '%c'", c); + if (digit == npos) { + throw Error("invalid character in Base64 string: '%c' in '%s'", c, s.data()); + } bits += 6; d = d << 6 | digit;