fix: always zero-terminate idna output

This commit is contained in:
Ben Noordhuis 2024-01-18 14:51:40 +01:00 committed by Santiago Gimeno
parent bb6fbcf6e7
commit fd08591bf9
No known key found for this signature in database
GPG Key ID: F28C3C8DA33C03BE
2 changed files with 7 additions and 2 deletions

View File

@ -356,9 +356,10 @@ ssize_t uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
return rc;
}
if (d < de)
*d++ = '\0';
if (d >= de)
return UV_EINVAL;
*d++ = '\0';
return d - ds; /* Number of bytes written. */
}

View File

@ -100,6 +100,7 @@ TEST_IMPL(utf8_decode1) {
TEST_IMPL(utf8_decode1_overrun) {
const char* p;
char b[1];
char c[1];
/* Single byte. */
p = b;
@ -113,6 +114,9 @@ TEST_IMPL(utf8_decode1_overrun) {
ASSERT_EQ((unsigned) -1, uv__utf8_decode1(&p, b + 1));
ASSERT_PTR_EQ(p, b + 1);
b[0] = 0x7F;
ASSERT_EQ(UV_EINVAL, uv__idna_toascii(b, b + 1, c, c + 1));
return 0;
}