From: Aki Tuomi Date: Wed, 10 Jun 2026 12:02:42 +0000 (+0000) Subject: lib: punycode - Use const unsigned char* input in punycode_decode() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=025a0d18a958730cee4a1908359bab8bb6cdafc5;p=thirdparty%2Fdovecot%2Fcore.git lib: punycode - Use const unsigned char* input in punycode_decode() --- diff --git a/src/lib-mail/rfc822-parser.c b/src/lib-mail/rfc822-parser.c index 2cee47480c..9af6ba12f8 100644 --- a/src/lib-mail/rfc822-parser.c +++ b/src/lib-mail/rfc822-parser.c @@ -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 == '.') diff --git a/src/lib/punycode.c b/src/lib/punycode.c index 41fe2ea514..4d2dbc066c 100644 --- a/src/lib/punycode.c +++ b/src/lib/punycode.c @@ -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); } diff --git a/src/lib/punycode.h b/src/lib/punycode.h index 40adf3b78f..62e718dd0a 100644 --- a/src/lib/punycode.h +++ b/src/lib/punycode.h @@ -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 diff --git a/src/lib/test-punycode.c b/src/lib/test-punycode.c index 434ef5fef2..b8a20a8caf 100644 --- a/src/lib/test-punycode.c +++ b/src/lib/test-punycode.c @@ -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); }