Author: miguel
Date: 2007-01-01 22:45:01 -0500 (Mon, 01 Jan 2007)
New Revision: 70334

Modified:
   trunk/mono/mono/metadata/ChangeLog
   trunk/mono/mono/metadata/marshal.c
Log:
2007-01-01  Miguel de Icaza  <[EMAIL PROTECTED]>

        * marshal.c (mono_string_to_byvalwstr): Fix this routine.   The
        string is null terminated, but only cut the string short if it
        overflows the buffer.   
        
        (mono_string_to_byvalstr): Also fix this routine.   The code here
        was not properly terminating a string (it was only terminated
        because of the previous catch-all memset). 

        I left the memset, because I do not know if applications expect
        the runtime to clear this region. 

        Fixes #79944.



Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog  2007-01-02 03:44:42 UTC (rev 70333)
+++ trunk/mono/mono/metadata/ChangeLog  2007-01-02 03:45:01 UTC (rev 70334)
@@ -1,5 +1,18 @@
 2007-01-01  Miguel de Icaza  <[EMAIL PROTECTED]>
 
+       * marshal.c (mono_string_to_byvalwstr): Fix this routine.   The
+       string is null terminated, but only cut the string short if it
+       overflows the buffer.   
+       
+       (mono_string_to_byvalstr): Also fix this routine.   The code here
+       was not properly terminating a string (it was only terminated
+       because of the previous catch-all memset). 
+
+       I left the memset, because I do not know if applications expect
+       the runtime to clear this region. 
+
+       Fixes #79944.
+
        * icall.c (ves_icall_System_Reflection_Assembly_InternalGetType):
        Clear the error before returning to unmanaged code to prevent the
        runtime from being confused later on (fixes  80420).

Modified: trunk/mono/mono/metadata/marshal.c
===================================================================
--- trunk/mono/mono/metadata/marshal.c  2007-01-02 03:44:42 UTC (rev 70333)
+++ trunk/mono/mono/metadata/marshal.c  2007-01-02 03:45:01 UTC (rev 70334)
@@ -966,7 +966,6 @@
        g_assert (size > 0);
 
        memset (dst, 0, size);
-       
        if (!src)
                return;
 
@@ -975,7 +974,8 @@
        memcpy (dst, s, len);
        g_free (s);
 
-       *((char *)dst + size - 1) = 0;
+       if (len >= size)
+               len--;
 }
 
 /**
@@ -984,8 +984,9 @@
  * @src: the MonoString to copy.
  * @size: the maximum number of bytes to copy.
  *
- * Copies the MonoString pointed to by @src as a utf16 string
- * into @dst, it copies at most @size bytes into the destination.
+ * Copies the MonoString pointed to by @src as a utf16 string into
+ * @dst, it copies at most @size bytes into the destination (including
+ * a terminating 16-bit zero terminator).
  */
 void
 mono_string_to_byvalwstr (gpointer dst, MonoString *src, int size)
@@ -1001,9 +1002,10 @@
        }
 
        len = MIN (size, (mono_string_length (src)));
-       memcpy (dst, mono_string_chars (src), len * 2);
-
-       *((gunichar2 *)dst + len - 1) = 0;
+       memcpy (dst, mono_string_chars (src), size * 2);
+       if (size <= mono_string_length (src))
+               len--;
+       *((gunichar2 *) dst + len) = 0;
 }
 
 void

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to