]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveconf: Use key_ends_with to compare suffixes
authorAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 14 Aug 2018 12:24:56 +0000 (15:24 +0300)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 14 Aug 2018 12:26:57 +0000 (15:26 +0300)
Fixes key hiding.

Broken in 1518e085

src/config/doveconf.c

index f4cc593035f3b9bcb63b18bd9f4ab801eff09ff4..13eb492592b356636665596d5f357a4e5522db3e 100644 (file)
@@ -239,6 +239,14 @@ hide_url_userpart_from_value(struct ostream *output, const char **_ptr,
        return TRUE;
 }
 
+static inline bool key_ends_with(const char *key, const char *eptr,
+                                const char *suffix)
+{
+       /* take = into account */
+       size_t n = strlen(suffix)+1;
+       return (eptr-key > (ptrdiff_t)n && str_begins(eptr-n, suffix));
+}
+
 static bool
 hide_secrets_from_value(struct ostream *output, const char *key,
                        const char *value)
@@ -246,8 +254,8 @@ hide_secrets_from_value(struct ostream *output, const char *key,
        bool ret = FALSE, quote = value_need_quote(value);
        const char *ptr, *optr, *secret;
        if (*value != '\0' &&
-           ((value-key > 8 && str_begins(value-9, "_password")) ||
-            (value-key > 7 && str_begins(value-8, "_api_key")) ||
+           (key_ends_with(key, value, "_password") ||
+            key_ends_with(key, value, "_api_key") ||
             str_begins(key, "ssl_key") ||
             str_begins(key, "ssl_dh"))) {
                o_stream_nsend_str(output, "# hidden, use -P to show it");