]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dcrypt: Fix ostream-encrypt error handling
authorAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 18 Feb 2025 13:00:04 +0000 (15:00 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 25 Feb 2025 10:09:39 +0000 (10:09 +0000)
Stream errno was not always set

src/lib-dcrypt/ostream-encrypt.c

index 3b213243f70397e022d337effb40f11fa0d60d8e..ebba0186eba874a80da134e24a112df51de3cd7b 100644 (file)
@@ -539,6 +539,7 @@ o_stream_encrypt_sendv(struct ostream_private *stream,
 
                        if (!dcrypt_ctx_sym_update(estream->ctx_sym, ptr + off,
                                                   bl, &buf, &error)) {
+                               stream->ostream.stream_errno = EIO;
                                io_stream_set_error(&stream->iostream,
                                                    "Encryption failure: %s",
                                                    error);
@@ -549,6 +550,7 @@ o_stream_encrypt_sendv(struct ostream_private *stream,
                                /* update mac */
                                if (!dcrypt_ctx_hmac_update(estream->ctx_mac,
                                        buf.data, buf.used, &error)) {
+                                       stream->ostream.stream_errno = EIO;
                                        io_stream_set_error(&stream->iostream,
                                                "MAC failure: %s", error);
                                        return -1;
@@ -589,6 +591,7 @@ o_stream_encrypt_finalize(struct ostream_private *stream)
        buffer_t *buf = t_buffer_create(
                dcrypt_ctx_sym_get_block_size(estream->ctx_sym));
        if (!dcrypt_ctx_sym_final(estream->ctx_sym, buf, &error)) {
+               stream->ostream.stream_errno = EIO;
                io_stream_set_error(&estream->ostream.iostream,
                                    "Encryption failure: %s", error);
                return -1;
@@ -600,6 +603,7 @@ o_stream_encrypt_finalize(struct ostream_private *stream)
                        IO_STREAM_ENC_INTEGRITY_HMAC)) {
                        if (!dcrypt_ctx_hmac_update(estream->ctx_mac, buf->data,
                                                    buf->used, &error)) {
+                               stream->ostream.stream_errno = EIO;
                                io_stream_set_error(&estream->ostream.iostream,
                                                    "MAC failure: %s", error);
                                return -1;
@@ -615,6 +619,7 @@ o_stream_encrypt_finalize(struct ostream_private *stream)
        if ((estream->flags & IO_STREAM_ENC_INTEGRITY_HMAC) ==
                IO_STREAM_ENC_INTEGRITY_HMAC) {
                if (!dcrypt_ctx_hmac_final(estream->ctx_mac, buf, &error)) {
+                       stream->ostream.stream_errno = EIO;
                        io_stream_set_error(&estream->ostream.iostream,
                                            "MAC failure: %s", error);
                        return -1;