Base64: report byte as positive integer

A baseline difference between arm64 and x86 showed up. We would
print a wrong character as negative value on x86 due to chars
being signed by default. Force an unsigned interpretation which
is also more reasonable because we'd have never indexed the
base64 table with -112

    -XXXXXXXXXX.XXXXXX      XXXXXXXXXXX     131.243.99.154  3288 193.159.183.138 80      base64_illegal_encoding character -112 ignored by Base64 decoding       F       zeek    -
    +XXXXXXXXXX.XXXXXX      XXXXXXXXXXX     131.243.99.154  3288 193.159.183.138 80      base64_illegal_encoding character 144 ignored by Base64 decoding        F       zeek    -

Fixes more of #2742
This commit is contained in:
Arne Welzel 2023-02-02 14:53:28 +01:00
parent c998cf697a
commit 5dc54fb40e
3 changed files with 22 additions and 4 deletions

View file

@ -184,17 +184,17 @@ int Base64Converter::Decode(int len, const char* data, int* pblen, char** pbuf)
if ( dlen >= len )
break;
if ( data[dlen] == '=' )
unsigned char c = (unsigned char)data[dlen];
if ( c == '=' )
++base64_padding;
int k = base64_table[(unsigned char)data[dlen]];
int k = base64_table[c];
if ( k >= 0 )
base64_group[base64_group_next++] = k;
else
{
if ( ++errored == 1 )
IllegalEncoding(
util::fmt("character %d ignored by Base64 decoding", (int)(data[dlen])));
IllegalEncoding(util::fmt("character %d ignored by Base64 decoding", (int)c));
}
++dlen;

View file

@ -0,0 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error: character 94 ignored by Base64 decoding
error: error in decoding string ^#@!@##$!===
error: character 237 ignored by Base64 decoding
error: error in decoding string íîï===
PASS
PASS

View file

@ -0,0 +1,11 @@
# @TEST-EXEC: zeek -b %INPUT >out 2>&1
# @TEST-EXEC: btest-diff out
event zeek_init()
{
local r1 = decode_base64("^#@!@##$!===");
print |r1| > 0 ? "FAIL" : "PASS";
local r2 = decode_base64("\xed\xee\xef===");
print |r2| > 0 ? "FAIL" : "PASS";
}