]> git.ipfire.org Git - thirdparty/bacula.git/commit
Fix wrong length returned by base64_to_bin(), rewrite the function
authorAlain Spineux <alain@baculasystems.com>
Tue, 2 Aug 2022 11:51:33 +0000 (13:51 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:59 +0000 (13:56 +0200)
commit808e67e98ac3b659914a801e35ec7bb83bdd03fa
tree07e525f3416558b1c8e67a1c4c91c47e470aeec0
parente1a8a3771a397acb9e2dd2d620b57a4587dc47ab
Fix wrong length returned by base64_to_bin(), rewrite the function

- base64_to_bin() was handling the '=' padding char as data,
  making the output longer when padding was used.
- If you had no padding, this was ok
- Or if you were knowing the length of the output to cut it at the right
  length this was ok too
- The output buffer had to be a little longer too
- The function base64_init() has been removed and 'base64_map' is
  initialized with a static table
- The function has been rewritten
  - ignore spaces in the input (space, tab, newline), can be a multi-line input
  - stop when a '\0', a '=' (padding) or srclen depending what is hit first
  - return 0 when the output string is too short or invalid char are fount
    in the output
  - dest_size don't need to be bigger, the exact length is ok
  - the output string is not ended with '\0', has it is supposed to be binary data
- The other usage of base64_to_bin() in the code have been fixed when needed
- Add plenty of test
==== Starting base64_test ... ====
OK  test bin_to_base64
OK  test bin_to_base64 content
OK  test base64_to_bin
OK  test base64_to_bin content
OK  test base64 encode decode for multiple lengths
OK  test base64 decode base64 with multiple spaces
OK  test base64 buffer too small 1
OK  test base64 buffer too small 2
OK  test base64 padding YQ==
OK  test base64 padding YQ=
OK  test base64 padding YQ
OK  test base64 padding YQ==
OK  test base64 padding YQ=
OK  test base64 padding YQ
OK  test base64 truncated padding YQ== 3
OK  test base64 truncated padding YQ== 2
OK  test base64 invalid char 1
OK  test base64 invalid char 2
OK  test base64 invalid char 3
OK  test base64 invalid char after the padding
OK  Checking bin_to_base64 encoded length
OK  Checking bin_to_base64 encoded data
OK  Checking base64_to_bin decoded length
OK  Checking base64_to_bin decoded data
OK  Checking base64_to_bin decoded length - encoded
OK  Checking base64_to_bin decoded data - encoded
OK  Checking to_base64 encode length
OK  Checking to_base64 encoded data
OK  Checking from_base64 decoded data
OK  Checking from_base64 decoded length
OK  Checking from_base64 decoded data - encoded
OK  Checking from_base64 decoded length - encoded

==== Report ====
Result 32/32 OK
bacula/src/lib/base64.c
bacula/src/lib/protos.h