basenc: ensure partial padding with newlines induces an error

* src/basenc.c (has_padding): A more robust helper to
identify padding in the presence of trailing newlines.
(do_decode): Use has_padding() rather than just looking
at the last character.
* tests/basenc/base64.pl: Fully test commit v9.4-53-g378dc38f4
by ensuring partially padded data is diagnosed.
baddecode9 is the case fixed in this commit.
* NEWS: Mention the bug fix.
This commit is contained in:
Pádraig Brady
2025-09-08 18:22:20 +01:00
parent 42c4578b49
commit d9b68362ed
3 changed files with 29 additions and 3 deletions

View File

@@ -122,10 +122,12 @@ sub gen_tests($)
if ($prog eq "base64")
{
push @Tests, (
['paddec1', '--decode', {IN=>'aQ'}, {OUT=>"i"}],
['paddec2', '--decode', {IN=>'Zzw'}, {OUT=>"g<"}],
['paddec3', '--decode', {IN=>'MTIzNA==MTIzNA'}, {OUT=>"12341234"}],
['paddec4', '--decode', {IN=>"MTIzNA==\nMTIzNA"}, {OUT=>"12341234"}],
['baddecode', '--decode', {IN=>'a'}, {OUT=>""},
{ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
['paddecode2', '--decode', {IN=>'aQ'}, {OUT=>"i"}],
['paddecode3', '--decode', {IN=>'Zzw'}, {OUT=>"g<"}],
['baddecode4', '--decode', {IN=>'Zz='}, {OUT=>"g"},
{ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
['baddecode5', '--decode', {IN=>'Z==='}, {OUT=>""},
@@ -133,6 +135,10 @@ sub gen_tests($)
['baddecode6', '--decode', {IN=>'SB=='}, {OUT=>"H"},
{ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
['baddecode7', '--decode', {IN=>'SGVsbG9='}, {OUT=>"Hello"},
{ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
['baddecode8', '--decode', {IN=>'MTIzNA='}, {OUT=>"1234"},
{ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
['baddecode9', '--decode', {IN=>"MTIzNA=\n"}, {OUT=>"1234"},
{ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}]
);
}