List:Commits« Previous MessageNext Message »
From:jwinstead Date:January 2 2008 7:23pm
Subject:Connector/ODBC 3.51 commit: r975 - branches/guffert/util
View as plain text  
Modified:
   branches/guffert/util/stringutil.c
Log:
Prevent possible endless loops in string conversions when invalid characters
are encountered, and remove some dead code.


Modified: branches/guffert/util/stringutil.c
===================================================================
--- branches/guffert/util/stringutil.c	2008-01-02 16:02:24 UTC (rev 974)
+++ branches/guffert/util/stringutil.c	2008-01-02 19:23:07 UTC (rev 975)
@@ -96,12 +96,24 @@
   {
     if (sizeof(SQLWCHAR) == 4)
     {
-      pos+= utf8toutf32(pos, (UTF32 *)(out + i++));
+      int consumed= utf8toutf32(pos, (UTF32 *)(out + i++));
+      pos+= consumed;
+      if (!consumed)
+      {
+        *errors+= 1;
+        break;
+      }
     }
     else
     {
       UTF32 u32;
-      pos+= utf8toutf32(pos, &u32);
+      int consumed= utf8toutf32(pos, &u32);
+      pos+= consumed;
+      if (!consumed)
+      {
+        *errors+= 1;
+        break;
+      }
       i+= utf32toutf16(u32, (UTF16 *)(out + i));
     }
   }
@@ -168,7 +180,13 @@
     else
     {
       UTF32 u32;
-      str+= utf16toutf32((UTF16 *)str, &u32);
+      int consumed= utf16toutf32((UTF16 *)str, &u32);
+      str+= consumed;
+      if (!consumed)
+      {
+        *errors+= 1;
+        break;
+      }
       u8_len= utf32toutf8(u32, u8);
     }
 
@@ -226,7 +244,10 @@
     for (i= 0; str < str_end; )
     {
       UTF32 u32;
-      str+= utf16toutf32((UTF16 *)str, &u32);
+      int consumed= utf16toutf32((UTF16 *)str, &u32);
+      str+= consumed;
+      if (!consumed)
+        break;
       i+= utf32toutf8(u32, u8 + i);
     }
   }
@@ -256,11 +277,19 @@
   for (i= 0, pos= out, out_end= out + out_max; i < in_len && pos < out_end;
)
   {
     if (sizeof(SQLWCHAR) == 4)
-      i+= utf8toutf32(in + i, (UTF32 *)pos++);
+    {
+      int consumed= utf8toutf32(in + i, (UTF32 *)pos++);
+      i+= consumed;
+      if (!consumed)
+        break;
+    }
     else
     {
       UTF32 u32;
-      i+= utf8toutf32(in + i, &u32);
+      int consumed= utf8toutf32(in + i, &u32);
+      i+= consumed;
+      if (!consumed)
+        break;
       pos+= utf32toutf16(u32, (UTF16 *)pos);
     }
   }
@@ -311,7 +340,7 @@
   return conv;
 }
 
- 
+
 /**
   Convert a SQLWCHAR to a SQLCHAR in the specified character set. This
   variation uses a pre-allocated buffer.
@@ -352,7 +381,13 @@
     else
     {
       UTF32 u32;
-      str+= utf16toutf32((UTF16 *)str, &u32);
+      int consumed= utf16toutf32((UTF16 *)str, &u32);
+      str+= consumed;
+      if (!consumed)
+      {
+        *errors+= 1;
+        break;
+      }
       u8_len= utf32toutf8(u32, u8);
     }
 
@@ -363,24 +398,6 @@
 
   out[i]= '\0';
 
-  for (i= 0; str < str_end; )
-  {
-    if (sizeof(SQLWCHAR) == 4)
-    {
-      u8_len= utf32toutf8((UTF32)*str++, u8);
-    }
-    else
-    {
-      UTF32 u32;
-      str+= utf16toutf32((UTF16 *)str, &u32);
-      u8_len= utf32toutf8(u32, u8);
-    }
-
-    i+= copy_and_convert((char *)out + i, out_bytes - i, charset_info,
-                         (char *)u8, u8_len, utf8_charset_info, &used_bytes,
-                         &used_chars, errors);
-  }
-
   return i;
 }
 

Thread
Connector/ODBC 3.51 commit: r975 - branches/guffert/utiljwinstead2 Jan