diff --git a/lib/wind/punycode.c b/lib/wind/punycode.c index ccd79beb8..0e4544520 100644 --- a/lib/wind/punycode.c +++ b/lib/wind/punycode.c @@ -77,7 +77,8 @@ adapt(unsigned delta, unsigned numpoints, int first) * * @param in an UCS4 string to convert * @param in_len the length of in. - * @param out the resulting puny-coded string. + * @param out the resulting puny-coded string. The string is not NUL + * terminatied. * @param out_len before processing out_len should be the length of * the out variable, after processing it will be the length of the out * string. @@ -107,19 +108,24 @@ wind_punycode_label_toascii(const uint32_t *in, size_t in_len, out[o++] = in[i]; } } + if (o == i) { + *out_len = o; + return 0; + } b = h; if (b > 0) { if (o >= *out_len) return WIND_ERR_OVERRUN; out[o++] = 0x2D; } - while (h < in_len) { - if (o + 4 >= *out_len) - return WIND_ERR_OVERRUN; - memmove(out + 4, out, o); - memcpy(out, "xn--", 4); - o += 4; + if (o + 4 >= *out_len) + return WIND_ERR_OVERRUN; + memmove(out + 4, out, o); + memcpy(out, "xn--", 4); + o += 4; + + while (h < in_len) { m = (unsigned)-1; for (i = 0; i < in_len; ++i) if(in[i] < m && in[i] >= n)