]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: uri-util - Add uri_char_sanitize() and use it in error messages.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Fri, 15 Oct 2021 19:08:50 +0000 (21:08 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 17 Jan 2022 11:52:09 +0000 (13:52 +0200)
src/lib-imap/imap-url.c
src/lib/uri-util.c
src/lib/uri-util.h

index 6da6e21752832157243c7febfc7ed46decfe40fa..5213fd1857e8c3879f72ff99174c74547c114632 100644 (file)
@@ -231,7 +231,9 @@ static int imap_url_parse_iserver(struct imap_url_parser *url_parser)
                        for (p += 6; *p != '\0'; p++) {
                                if (*p == ';' || *p == ':') {
                                        parser->error = t_strdup_printf(
-                                               "Stray '%c' in userinfo `%s'", *p, auth.enc_userinfo);
+                                               "Stray %s in userinfo `%s'",
+                                               uri_char_sanitize(*p),
+                                               auth.enc_userinfo);
                                        return -1;
                                }
                        }
index 4e73d6d7648c713da3e3c4aff86af096d9bed34a..e4dc419b8aeacf608485371340ff3e7564a07f08 100644 (file)
@@ -150,7 +150,8 @@ uri_parse_pct_encoded_data(struct uri_parser *parser,
        if (value < 0) {
                parser->error = p_strdup_printf(
                        parser->pool,
-                       "Expecting hex digit after '%%', but found '%c'", **p);
+                       "Expecting hex digit after '%%', but found %s",
+                       uri_char_sanitize(**p));
                return -1;
        }
 
@@ -161,8 +162,8 @@ uri_parse_pct_encoded_data(struct uri_parser *parser,
        if (value < 0) {
                parser->error = p_strdup_printf(
                        parser->pool,
-                       "Expecting hex digit after '%%%c', but found '%c'",
-                       *((*p)-1), **p);
+                       "Expecting hex digit after '%%%c', but found %s",
+                       *((*p)-1), uri_char_sanitize(**p));
                return -1;
        }
 
index b129730311f56d87c8c5791b914400db92750d8f..cc8febac5ada2a88de7a13220b7f5297f36ce09f 100644 (file)
@@ -38,6 +38,13 @@ struct uri_parser {
        bool allow_pct_nul:1;
 };
 
+static inline const char *uri_char_sanitize(unsigned char c)
+{
+       if (c >= 0x20 && c < 0x7F)
+               return t_strdup_printf("'%c'", c);
+       return t_strdup_printf("<0x%02x>", c);
+}
+
 /* Parse one instance of percent encoding. Returns 1 for success, 0 if none is
    present at the current parser position, and -1 in case of error. The decoded
    character is returned in ch_r upon success. */