Commit ce0d4532 authored by Tim Rühsen's avatar Tim Rühsen

Fix decoding with no ASCII chars but given delimiter

Reported-by: Florian Weimer
parent b77fd6e9
......@@ -144,7 +144,6 @@ int punycode_decode(
size_t b, j, in;
/* Initialize the state: */
n = initial_n;
out = i = 0;
max_out = *output_length > maxint ? maxint
......@@ -156,19 +155,21 @@ int punycode_decode(
/* copy the first b code points to the output. */
for (b = j = 0; j < input_length; ++j) if (delim(input[j])) b = j;
if (b > max_out) return punycode_big_output;
if (b >= max_out) return punycode_big_output;
for (j = 0; j < b; ++j) {
if (!basic(input[j])) return punycode_bad_input;
output[out++] = input[j];
}
for (j = b + (b > 0); j < input_length; ++j)
b += delim(input[b]);
for (j = b; j < input_length; ++j)
if (!basic(input[j])) return punycode_bad_input;
/* Main decoding loop: Start just after the last delimiter if any */
/* basic code points were copied; start at the beginning otherwise. */
for (in = b > 0 ? b + 1 : 0; in < input_length; ++out) {
for (in = b; in < input_length; ++out) {
/* in is the index of the next ASCII code point to be consumed, */
/* and out is the number of code points in the output array. */
......
......@@ -350,6 +350,14 @@ const test_t test[] = {
},
IDN2_OK
},
{
"Empty label",
"xn---.de",
{
0x2e, 0x64, 0x65, 0
},
IDN2_OK
},
};
static int debug = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment