An issue was discovered in x509/x509_verify.c in LibreSSL before 3.6.1, and in OpenBSD before 7.2 errata 001. x509_verify_ctx_add_chain does not store errors that occur during leaf certificate verification, and therefore an incorrect error is returned. This behavior occurs when there is an installed verification callback that instructs the verifier to continue upon detecting an invalid certificate.
https://github.com/openbsd/src/commit/4f94258c65a918ee3d8670e93916d15bf879e6ec
https://ftp.openbsd.org/pub/OpenBSD/patches/7.2/common/001_x509.patch.sig
https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.6.1-relnotes.txt