]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
var-expand-crypt: Defer creating key and iv in context
authorAki Tuomi <aki.tuomi@open-xchange.com>
Sun, 17 Nov 2024 10:04:15 +0000 (12:04 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:14 +0000 (12:34 +0200)
Simplifies next change.

src/plugins/var-expand-crypt/var-expand-crypt-plugin.c

index 3172102d7802b6aabcb164a7570a0a6d2a365df8..852b9c43840d842ff75878f0265c521b9708c406 100644 (file)
@@ -66,9 +66,8 @@ static int var_expand_crypt_settings(struct var_expand_state *state,
                                     const char **error_r)
 {
        const char *iv;
+       const char *enckey = NULL;
 
-       ctx->iv = t_buffer_create(32);
-       ctx->enckey = t_buffer_create(32);
        ctx->algo = VAR_EXPAND_CRYPT_DEFAULT_ALGO;
 
        struct var_expand_parameter_iter_context *iter =
@@ -89,14 +88,17 @@ static int var_expand_crypt_settings(struct var_expand_state *state,
                                                               error_r) < 0) {
                                return -1;
                        }
+                       ctx->iv = t_buffer_create(strlen(iv) / 2);
                        hex_to_binary(iv, ctx->iv);
                } else if (strcmp(key, "key") == 0) {
-                       const char *enckey;
                        if (var_expand_parameter_string_or_var(state, par, &enckey,
                                                               error_r) < 0) {
                                return -1;
                        }
-                       hex_to_binary(enckey, ctx->enckey);
+                       if (enckey == NULL || *enckey == '\0') {
+                               *error_r = "Empty encryption key";
+                               return -1;
+                       }
                } else if (strcmp(key, "raw") == 0) {
                        if (var_expand_parameter_bool_or_var(state, par, &ctx->raw,
                                                             error_r) < 0)
@@ -105,6 +107,14 @@ static int var_expand_crypt_settings(struct var_expand_state *state,
                        ERROR_UNSUPPORTED_KEY(key);
        }
 
+       if (enckey == NULL) {
+               *error_r = "Encryption key missing";
+               return -1;
+       }
+
+       ctx->enckey = t_buffer_create(strlen(enckey) / 2);
+       hex_to_binary(enckey, ctx->enckey);
+
        ERROR_IF_NO_TRANSFER_TO(stmt->function);
 
        ctx->input = state->transfer;