Re: gdk_selection.c:sanitize_ctext is broken in 1.2.9



Vlad Harchev <hvv hippo ru> writes:

> On 13 Mar 2001, Owen Taylor wrote:

> > OK, looking again at the Xlib code and the CTEXT spec, it appears that
> > the CTEXT spec was at some point extended to accomodate this (section
> > 6) but the initial section that describes what characters are allowed
> > was never updated :-(.
> > 
> > Unfortunately, according to the spec, anything is allowed in an
> > extended segment, including all of C0 and C1, so probably we need to
> > add explicit recognition of extended segments to sanitize_ctext().

[...]

>  Thanks you for this.
> 
>  I want to add that I just tried gtk+-1.2.9 and found that I can't cut and
> paste russian to/from any gtk widget due to brokeness of sanitize_ctext! That
> hackish patch fixes the problem. So the problem should be definitely fixed!

Patch appended fixes cut-and-paste of Russian for me.
 
>  Also small addition: by the "old XFree servers" ANY XFree with version <=
> 4.0.1 was ment in my mail.

I dont' understand what you meant by this. Are there problems that occcur
with old XFree86 libraries (server is irrelevant) that don't occur with
current XFree86 libraries?

                                        Owen

Index: gdkselection.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/Attic/gdkselection.c,v
retrieving revision 1.6.2.6
diff -u -r1.6.2.6 gdkselection.c
--- gdkselection.c	2001/02/22 20:38:12	1.6.2.6
+++ gdkselection.c	2001/03/15 19:09:51
@@ -208,16 +208,40 @@
   gchar *result = g_malloc (*length + 1);
   gint out_length = 0;
   gint i;
+  const guchar *ustr = (const guchar *)str;
 
   for (i=0; i < *length; i++)
     {
-      guchar c = ((guchar *)str)[i];
+      guchar c = ustr[i];
       
       if (c == '\r')
 	{
 	  result[out_length++] = '\n';
-	  if (i + 1 < *length && str[i + 1] == '\n')
+	  if (i + 1 < *length && ustr[i + 1] == '\n')
 	    i++;
+	}
+      else if (c == 27 /* ESC */)
+	{
+	  /* Check for "extended segments, which can contain arbitrary
+	   * octets. See CTEXT spec, section 6.
+	   */
+
+	  if (i + 5 < *length &&
+	      ustr[i + 1] == '%' &&
+	      ustr[i + 2] == '/' &&
+	      (ustr[i + 3] >= 48 && ustr[i + 3] <= 52) &&
+	      ustr[i + 4] >= 128 &&
+	      ustr[i + 5] >= 128)
+	    {
+	      int extra_len = 6 + (ustr[i + 4] - 128) * 128 + ustr[i + 5] - 128;
+	      extra_len = MAX (extra_len, *length - i);
+
+	      memcpy (result + out_length, ustr + i, extra_len);
+	      out_length += extra_len;
+	      i += extra_len - 1;
+	    }
+	  else
+	    result[out_length++] = c;	    
 	}
       else if (c == '\n' || c == '\t' || c == 27 /* ESC */ ||
 	       (c >= 32 && c <= 127) ||	/* GL */




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]