]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: punycode - Use const unsigned char* input in punycode_decode()
authorAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 10 Jun 2026 12:02:42 +0000 (12:02 +0000)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Tue, 23 Jun 2026 15:07:48 +0000 (15:07 +0000)
src/lib-mail/rfc822-parser.c
src/lib/punycode.c
src/lib/punycode.h
src/lib/test-punycode.c

index 2cee47480c5bd18150df8fd29bcc3226f004b659..9af6ba12f83145b31c10ca775e7f8ba62ead2ec0 100644 (file)
@@ -426,7 +426,7 @@ void rfc822_decode_punycode(const char *input, size_t len, string_t *result)
                        delim = end;
                if (str_begins(pos, "xn--", &value)) {
                        str_truncate(decoded, 0);
-                       if (punycode_decode(value, delim - value, result) < 0)
+                       if (punycode_decode((const unsigned char *)value, delim - value, result) < 0)
                                /* Consider it as data */
                                str_append_data(result, pos, delim - pos + 1);
                        else if (*delim == '.')
index 41fe2ea514b463042f6a0dc32e3d7f8805464a39..4d2dbc066c09f7a610af2e415df876733438ad33 100644 (file)
@@ -53,15 +53,15 @@ static unsigned int adapt(unsigned int delta, unsigned int numpoints, bool first
 }
 
 /* Decodes a punycoded string into output, or returns -1 on error. */
-int punycode_decode(const char *input, size_t len, string_t *output)
+int punycode_decode(const unsigned char *input, size_t len, string_t *output)
 {
        ARRAY(unichar_t) label;
        size_t i = 0;
        size_t out = 0;
        unsigned int n = initialN, bias = initialBias;
-       const char *delim = NULL;
-       const char *end = CONST_PTR_OFFSET(input, len);
-       const char *ptr = input;
+       const unsigned char *delim = NULL;
+       const unsigned char *end = CONST_PTR_OFFSET(input, len);
+       const unsigned char *ptr = input;
        t_array_init(&label, len);
 
        /* find the rightmost delimiter, if present in string */
@@ -74,12 +74,12 @@ int punycode_decode(const char *input, size_t len, string_t *output)
        i_assert(delim <= end);
 
        for (ptr = input; ptr < delim; ptr++) {
-               if ((unsigned char)*ptr >= 0x80)
+               if (*ptr >= 0x80)
                        /* Has non-ascii input, this cannot be punycoded. */
                        return -1;
                i_assert(out < sizeof(label));
                /* Add basic code points to label */
-               unichar_t ch = (unsigned char)*ptr;
+               unichar_t ch = *ptr;
                array_push_back(&label, &ch);
        }
 
index 40adf3b78feedc22a74fbdf1faff390acfc09b3d..62e718dd0ab31184b222773fdaa9d0390baf141a 100644 (file)
@@ -3,6 +3,6 @@
 
 /* Parse input as a punycode-encoded string and append it to
    output. Returns 0 on success and -1 on failure. */
-int punycode_decode(const char *input, size_t len, string_t *output);
+int punycode_decode(const unsigned char *input, size_t len, string_t *output);
 
 #endif
index 434ef5fef26ddc7cdf848cbe196738c838ede3d5..b8a20a8cafc2252cf925c22db1e5b42d902ce53c 100644 (file)
@@ -36,7 +36,7 @@ static void test_punycode_decode(void)
        test_begin("punycode decoding");
        for (i = 0; i < N_ELEMENTS(cases); i ++) {
                str_truncate(r, 0);
-               int ret = punycode_decode(cases[i].in, strlen(cases[i].in), r);
+               int ret = punycode_decode((const unsigned char *)cases[i].in, strlen(cases[i].in), r);
                test_assert_idx(ret == cases[i].ret, i);
                test_assert_strcmp_idx(str_c(r), cases[i].out, i);
        }