]> git.ipfire.org Git - thirdparty/openssl.git/commit
Improve base64 BIO correctness and error reporting
authorViktor Dukhovni <openssl-users@dukhovni.org>
Wed, 21 Aug 2024 14:43:33 +0000 (00:43 +1000)
committerTomas Mraz <tomas@openssl.org>
Fri, 30 Aug 2024 13:09:10 +0000 (15:09 +0200)
commit0cd9dd703ea575699b2d3cd74f1b8224447f4352
tree413730537872fb469666510e32900947a1958add
parentd1c2c054a4b585eed8c883367d80e2a972c4846f
Improve base64 BIO correctness and error reporting

Also improve related documentation.

- The BIO_FLAGS_BASE64_NO_NL flag did not behave as advertised, only
  leading and trailing, but not internal, whitespace was supported:

      $ echo 'AA AA' | openssl base64 -A -d | wc -c
      0

- Switching from ignored leading input to valid base64 input misbehaved
  when the length of the skipped input was one more than the length of
  the second and subsequent valid base64 lines in the internal 1k
  buffer:

    $ printf '#foo\n#bar\nA\nAAA\nAAAA\n' | openssl base64 -d | wc -c
    0

- When the underlying BIO is retriable, and a read returns less than
  1k of data, some of the already buffered input lines that could have
  been decoded and returned were retained internally for a retry by the
  caller.  This is somewhat surprising, and the new code decodes as many
  of the buffered lines as possible.  Issue reported by MichaƂ Trojnara.

- After all valid data has been read, the next BIO_read(3) should
  return 0 when the input was all valid or -1 if an error was detected.
  This now occurs in more consistently, but further tests and code
  refactoring may be needed to ensure this always happens.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25253)
crypto/evp/bio_b64.c
crypto/evp/encode.c
doc/man3/BIO_f_base64.pod
doc/man3/EVP_EncodeInit.pod
doc/man7/evp.pod
test/bio_base64_test.c [new file with mode: 0644]
test/build.info
test/recipes/90-test_bio_base64.t [new file with mode: 0644]