Skip to content

Commit 0f2d7e7

Browse files
bnoordhuissantigimeno
authored andcommitted
fix: always zero-terminate idna output
Fixes: GHSA-f74f-cvh7-c6q6
1 parent bb6fbcf commit 0f2d7e7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Diff for: src/idna.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,10 @@ ssize_t uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
356356
return rc;
357357
}
358358

359-
if (d < de)
360-
*d++ = '\0';
359+
if (d >= de)
360+
return UV_EINVAL;
361361

362+
*d++ = '\0';
362363
return d - ds; /* Number of bytes written. */
363364
}
364365

Diff for: test/test-idna.c

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ TEST_IMPL(utf8_decode1) {
100100
TEST_IMPL(utf8_decode1_overrun) {
101101
const char* p;
102102
char b[1];
103+
char c[1];
103104

104105
/* Single byte. */
105106
p = b;
@@ -113,6 +114,9 @@ TEST_IMPL(utf8_decode1_overrun) {
113114
ASSERT_EQ((unsigned) -1, uv__utf8_decode1(&p, b + 1));
114115
ASSERT_PTR_EQ(p, b + 1);
115116

117+
b[0] = 0x7F;
118+
ASSERT_EQ(UV_EINVAL, uv__idna_toascii(b, b + 1, c, c + 1));
119+
116120
return 0;
117121
}
118122

0 commit comments

Comments
 (0)