]> granicus.if.org Git - onig/commitdiff
add code point value check in xxx_code_to_mbclen()
authorK.Kosako <kosako@sofnec.co.jp>
Tue, 30 Jul 2019 03:23:34 +0000 (12:23 +0900)
committerK.Kosako <kosako@sofnec.co.jp>
Tue, 30 Jul 2019 03:23:34 +0000 (12:23 +0900)
src/utf16_be.c
src/utf16_le.c

index 7420a6dd1c1f3c25b0645911978d5283cb3dea81..b66d868a9c24d8af5d247469e1069724498a71a0 100644 (file)
@@ -164,7 +164,15 @@ utf16be_mbc_to_code(const UChar* p, const UChar* end ARG_UNUSED)
 static int
 utf16be_code_to_mbclen(OnigCodePoint code)
 {
-  return (code > 0xffff ? 4 : 2);
+  if (code > 0xffff) {
+    if (code > 0x10ffff)
+      return ONIGERR_INVALID_CODE_POINT_VALUE;
+    else
+      return 4;
+  }
+  else {
+    return 2;
+  }
 }
 
 static int
index c33dabda50cddd12fc389b375bad6b7766629739..cdc74b037ccface97c55d9b2e07147c3e2e634b4 100644 (file)
@@ -95,7 +95,15 @@ static const int EncLen_UTF16[] = {
 static int
 utf16le_code_to_mbclen(OnigCodePoint code)
 {
-  return (code > 0xffff ? 4 : 2);
+  if (code > 0xffff) {
+    if (code > 0x10ffff)
+      return ONIGERR_INVALID_CODE_POINT_VALUE;
+    else
+      return 4;
+  }
+  else {
+    return 2;
+  }
 }
 
 static int