Fix CVE-2024-24806
authorDominique Dumont <dod@debian.org>
Tue, 20 Feb 2024 17:28:54 +0000 (18:28 +0100)
committerDominique Dumont <dod@debian.org>
Tue, 20 Feb 2024 17:28:54 +0000 (18:28 +0100)
Bug: https://github.com/libuv/libuv/security/advisories/GHSA-f74f-cvh7-c6q6
Bug-Debian: https://bugs.debian.org/1063484
Origin: https://github.com/libuv/libuv
 git diff v1.48.0~5..v1.48.0~2

From upstream change log:
   Merge pull request from GHSA-f74f-cvh7-c6q6
    * fix: always zero-terminate idna output
    * fix: reject zero-length idna inputs
    * test: empty strings are not valid IDNA

See also https://github.com/libuv/libuv/security/advisories/GHSA-f74f-cvh7-c6q6

Gbp-Pq: Name fix-cve-2024-24806

src/idna.c
test/test-idna.c

index 93d982ca018f2d39d9c0ffab07998c2c637029eb..858b19d00ee4239879357f2ec0231cb6d84e4186 100644 (file)
@@ -274,6 +274,9 @@ long uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
   char* ds;
   int rc;
 
+  if (s == se)
+    return UV_EINVAL;
+
   ds = d;
 
   si = s;
@@ -308,8 +311,9 @@ long 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. */
 }
index f4fad9653df2cfcaad504f737e8d38b45a3d1c4d..37da38de2da85e5e97ea30ca6b85e6ad63124f7b 100644 (file)
@@ -99,6 +99,7 @@ TEST_IMPL(utf8_decode1) {
 TEST_IMPL(utf8_decode1_overrun) {
   const char* p;
   char b[1];
+  char c[1];
 
   /* Single byte. */
   p = b;
@@ -112,6 +113,10 @@ TEST_IMPL(utf8_decode1_overrun) {
   ASSERT_EQ((unsigned) -1, uv__utf8_decode1(&p, b + 1));
   ASSERT_EQ(p, b + 1);
 
+  b[0] = 0x7F;
+  ASSERT_EQ(UV_EINVAL, uv__idna_toascii(b, b + 0, c, c + 1));
+  ASSERT_EQ(UV_EINVAL, uv__idna_toascii(b, b + 1, c, c + 1));
+
   return 0;
 }
 
@@ -145,8 +150,8 @@ TEST_IMPL(idna_toascii) {
   /* Illegal inputs. */
   F("\xC0\x80\xC1\x80", UV_EINVAL);  /* Overlong UTF-8 sequence. */
   F("\xC0\x80\xC1\x80.com", UV_EINVAL);  /* Overlong UTF-8 sequence. */
+  F("", UV_EINVAL);
   /* No conversion. */
-  T("", "");
   T(".", ".");
   T(".com", ".com");
   T("example", "example");