Bug 3755 - [PATCH] twm can't handle 8-bit characters in .twmrc
Summary: [PATCH] twm can't handle 8-bit characters in .twmrc
Status: RESOLVED FIXED
Alias: None
Product: xorg
Classification: Unclassified
Component: App/twm (show other bugs)
Version: git
Hardware: Other Linux (All)
: high normal
Assignee: Xorg Project Team
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-12 05:24 UTC by Daniel Stone
Modified: 2005-10-08 19:15 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description FreeDesktop Bugzilla Database Corruption Fix User 2005-07-12 05:24:20 UTC
This is Debian bug 129896  
(http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=129896).  
  
Two alternate patches below by Tomohiro KUBOITA <kubota@surfchem0.riken.go.jp>;  
they are extracts from his message reproduced from   
http://marc.theaimsgroup.com/?l=xfree-i18n&m=97059124924489&w=2  
  
  
I suspect both patches qualify as trivial. Submitted in the spirit of "it's 
patched, so it should be fixed". 
----  
Hi,  
  
I found that the configuration-file reader of TWM is not 8-bit clean.  
It uses 'char' type (not 'unsigned char') to read configuration files   
and checks the validity of the read value using 'c <= 0' (lex.l 80).  
  
The following is a patch to fix the problem.  
  
---------------------------------------------------  
diff -ruN twm.orig/Imakefile twm.8bit/Imakefile  
--- twm.orig/Imakefile  Mon Sep  4 23:25:21 2000  
+++ twm.8bit/Imakefile  Wed Oct  4 01:21:32 2000  
@@ -53,7 +53,7 @@  
        echo ' * twm bindings file system.twmrc by the twm Imakefile.' >>$@  
        echo ' */' >>$@  
        echo '' >>$@  
-       echo 'char *defTwmrc[] = {' >>$@  
+       echo 'unsigned char *defTwmrc[] = {' >>$@  
        sed -f deftwmrc.sed <system.twmrc >>$@  
        echo '    (char *) 0 };' >>$@  
   
diff -ruN twm.orig/parse.c twm.8bit/parse.c  
--- twm.orig/parse.c    Mon Sep  4 23:25:21 2000  
+++ twm.8bit/parse.c    Wed Oct  4 01:21:38 2000  
@@ -77,10 +77,10 @@  
 static FILE *twmrc;  
 static int ptr = 0;  
 static int len = 0;  
-static char buff[BUF_LEN+1];  
-static char overflowbuff[20];          /* really only need one */  
+static unsigned char buff[BUF_LEN+1];  
+static unsigned char overflowbuff[20];         /* really only need one */  
 static int overflowlen;  
-static char **stringListSource, *currentString;  
+static unsigned char **stringListSource, *currentString;  
   
 static int doparse ( int (*ifunc)(void), char *srctypename, char *srcname );  
 static int twmFileInput ( void );  
@@ -94,7 +94,7 @@  
   
 int (*twmInputFunc)(void);  
   
-extern char *defTwmrc[];               /* default bindings */  
+extern unsigned char *defTwmrc[];              /* default bindings */  
   
   
 /***********************************************************************  
@@ -235,7 +235,7 @@  
 }  
   
 int ParseStringList (sl)  
-    char **sl;  
+    unsigned char **sl;  
 {  
     stringListSource = sl;  
     currentString = *sl;  
@@ -304,7 +304,7 @@  
     int c;  
 {  
     if (overflowlen < sizeof overflowbuff) {  
-       overflowbuff[overflowlen++] = (char) c;  
+       overflowbuff[overflowlen++] = (unsigned char) c;  
     } else {  
        twmrc_error_prefix ();  
        fprintf (stderr, "unable to unput character (%d)\n",  
diff -ruN twm.orig/parse.h twm.8bit/parse.h  
--- twm.orig/parse.h    Mon Sep  4 23:25:21 2000  
+++ twm.8bit/parse.h    Wed Oct  4 01:19:49 2000  
@@ -72,7 +72,7 @@  
 void put_pixel_on_root ( Pixel pixel );  
 extern void do_string_savecolor ( int colormode, char *s );  
 extern void do_var_savecolor ( int key );  
-extern int ParseStringList ( char **sl );  
+extern int ParseStringList ( unsigned char **sl );  
 extern int ParseTwmrc ( char *filename );  
 extern int parse_keyword ( char *s, int *nump );  
 extern void TwmOutput ( int c );  
---------------------------------------------------  
  
  
I also found that the problem is fixed with the following very   
simple patch.  
  
  
---------------------------------------------------  
diff -ruN twm.patch2/lex.l twm.patch3/lex.l  
--- twm.patch2/lex.l    Fri Sep 29 09:14:33 2000  
+++ twm.patch3/lex.l    Sat Sep 30 11:05:31 2000  
@@ -77,7 +77,7 @@  
        if (size == 0)  
                return (0);  
   
-       if ((c = (*twmInputFunc)()) <= 0)  
+       if ((c = (*twmInputFunc)()) == 0)  
                return (0);  
   
        buf[0] = c;  
---------------------------------------------------  
  
  
I would like to send one of them to patch@xfree86.org  
(I prefer the former patch).  However, I am not familiar   
with lex and yacc.  I might write a bad patch....  
  
Please check these patches.  Though I prefer the former  
patch, if someone recommends the latter one I may change  
my mind.
Comment 1 Alan Coopersmith 2005-10-09 00:30:16 UTC
Original reporter e-mail & comments lost in bugzilla disk death.
xorg-team archives show:

           Summary: twm can't handle 8-bit characters in .twmrc
           Product: xorg
           Version: CVS_head
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: App/twm
        AssignedTo: xorg-team at lists.x.org
        ReportedBy: neroden at twcny.rr.com


This is Debian bug 129896  
(http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=129896).  
  
Two alternate patches below by Tomohiro KUBOITA <kubota at surfchem0.riken.go.jp>;  
they are extracts from his message reproduced from   
http://marc.theaimsgroup.com/?l=xfree-i18n&m=97059124924489&w=2  
  
  
I suspect both patches qualify as trivial. Submitted in the spirit of "it's 
patched, so it should be fixed". 
----  
Hi,  
  
I found that the configuration-file reader of TWM is not 8-bit clean.  
It uses 'char' type (not 'unsigned char') to read configuration files   
and checks the validity of the read value using 'c <= 0' (lex.l 80).  
  
The following is a patch to fix the problem.  
  
---------------------------------------------------  
diff -ruN twm.orig/Imakefile twm.8bit/Imakefile  
--- twm.orig/Imakefile  Mon Sep  4 23:25:21 2000  
+++ twm.8bit/Imakefile  Wed Oct  4 01:21:32 2000  
@@ -53,7 +53,7 @@  
        echo ' * twm bindings file system.twmrc by the twm Imakefile.' >>$@  
        echo ' */' >>$@  
        echo '' >>$@  
-       echo 'char *defTwmrc[] = {' >>$@  
+       echo 'unsigned char *defTwmrc[] = {' >>$@  
        sed -f deftwmrc.sed <system.twmrc >>$@  
        echo '    (char *) 0 };' >>$@  
   
diff -ruN twm.orig/parse.c twm.8bit/parse.c  
--- twm.orig/parse.c    Mon Sep  4 23:25:21 2000  
+++ twm.8bit/parse.c    Wed Oct  4 01:21:38 2000  
@@ -77,10 +77,10 @@  
 static FILE *twmrc;  
 static int ptr = 0;  
 static int len = 0;  
-static char buff[BUF_LEN+1];  
-static char overflowbuff[20];          /* really only need one */  
+static unsigned char buff[BUF_LEN+1];  
+static unsigned char overflowbuff[20];         /* really only need one */  
 static int overflowlen;  
-static char **stringListSource, *currentString;  
+static unsigned char **stringListSource, *currentString;  
   
 static int doparse ( int (*ifunc)(void), char *srctypename, char *srcname );  
 static int twmFileInput ( void );  
@@ -94,7 +94,7 @@  
   
 int (*twmInputFunc)(void);  
   
-extern char *defTwmrc[];               /* default bindings */  
+extern unsigned char *defTwmrc[];              /* default bindings */  
   
   
 /***********************************************************************  
@@ -235,7 +235,7 @@  
 }  
   
 int ParseStringList (sl)  
-    char **sl;  
+    unsigned char **sl;  
 {  
     stringListSource = sl;  
     currentString = *sl;  
@@ -304,7 +304,7 @@  
     int c;  
 {  
     if (overflowlen < sizeof overflowbuff) {  
-       overflowbuff[overflowlen++] = (char) c;  
+       overflowbuff[overflowlen++] = (unsigned char) c;  
     } else {  
        twmrc_error_prefix ();  
        fprintf (stderr, "unable to unput character (%d)\n",  
diff -ruN twm.orig/parse.h twm.8bit/parse.h  
--- twm.orig/parse.h    Mon Sep  4 23:25:21 2000  
+++ twm.8bit/parse.h    Wed Oct  4 01:19:49 2000  
@@ -72,7 +72,7 @@  
 void put_pixel_on_root ( Pixel pixel );  
 extern void do_string_savecolor ( int colormode, char *s );  
 extern void do_var_savecolor ( int key );  
-extern int ParseStringList ( char **sl );  
+extern int ParseStringList ( unsigned char **sl );  
 extern int ParseTwmrc ( char *filename );  
 extern int parse_keyword ( char *s, int *nump );  
 extern void TwmOutput ( int c );  
---------------------------------------------------  
  
  
I also found that the problem is fixed with the following very   
simple patch.  
  
  
---------------------------------------------------  
diff -ruN twm.patch2/lex.l twm.patch3/lex.l  
--- twm.patch2/lex.l    Fri Sep 29 09:14:33 2000  
+++ twm.patch3/lex.l    Sat Sep 30 11:05:31 2000  
@@ -77,7 +77,7 @@  
        if (size == 0)  
                return (0);  
   
-       if ((c = (*twmInputFunc)()) <= 0)  
+       if ((c = (*twmInputFunc)()) == 0)  
                return (0);  
   
        buf[0] = c;  
---------------------------------------------------  
  
  
I would like to send one of them to patch at xfree86.org  
(I prefer the former patch).  However, I am not familiar   
with lex and yacc.  I might write a bad patch....  
  
Please check these patches.  Though I prefer the former  
patch, if someone recommends the latter one I may change  
my mind.          
Comment 2 Alan Coopersmith 2005-10-09 12:15:37 UTC
Fixes checked into CVS head - should be included in Xorg 6.9 & 7.0 RC1 releases.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.