[tex-k] header special extension proposal

Akira Kakuto kakuto at fsci.fuk.kindai.ac.jp
Wed Aug 17 06:44:01 CEST 2005


Hi Karl, Hendri

> > Many thanks for the simplification.
> > In the previous example, Hendri cannot use braces
> > in pre code and post code. In the next example, he can use "balanced"
> > braces:
> 
> The patch I have sent just before (as well as my original ones)
> has some security problems when the special does not satisfy
> Hendri's rule. Please replace with the following:

The previous one was also problematic.
I hope the next one is ok.
Sorry for disturbing many times.


--- dospecial.c.orig	Wed Aug 17 07:45:56 2005
+++ dospecial.c	Wed Aug 17 13:29:00 2005
@@ -393,7 +393,7 @@
 	 while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0)
 	    p++;
 	 q = p ;
-	 while (*p != '}')
+	 while (*p != '}' && *p != 0)
 	    p++;
 	 r = p-1 ;
 	 while ((*r <= ' ' || *r == ')') && r >= q)
@@ -403,31 +403,39 @@
 	 while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0)
 	    p++ ;
 	 if(strncmp(p, "pre", 3) == 0) {
-	    while(*p != '{')
+	    int bracecount = 1, numbytes = 0, j ;
+	    while(*p != '{' && *p != 0)
 	       p++ ;
-	    p++;
-	    r = p;
-	    while(*r != '}')
-	       r++ ;
-	    pre = (char *)malloc(r-p+1);
+	    if (*p != 0) p++;
+	    for(r = p; *r != 0; r++) {
+	       if (*r == '{') bracecount++ ;
+	       else if (*r == '}') bracecount-- ;
+	       if (bracecount == 0) break ;
+	       numbytes++ ;
+	    }
+	    pre = (char *)malloc(numbytes+1);
 	    r = pre ;
-	    while(*p != '}')
+	    for (j=0; j < numbytes; j++)
 	       *r++ = *p++;
 	    *r = 0;
-	    p++;
+	    if (*p != 0) p++;
 	 }
 	 while ((*p <= ' ' || *p == '=' || *p == '(') && *p != 0)
 	    p++ ;
 	 if(strncmp(p, "post", 4) == 0) {
-	    while(*p != '{')
+	    int bracecount = 1, numbytes = 0, j ;
+	    while(*p != '{' && *p != 0)
 	       p++ ;
-	    p++;
-	    r = p;
-	    while(*r != '}')
-	       r++ ;
-	    post = (char *)malloc(r-p+1);
+	    if (*p != 0) p++;
+	    for(r = p; *r != 0; r++) {
+	       if (*r == '{') bracecount++ ;
+	       else if (*r == '}') bracecount-- ;
+	       if (bracecount == 0) break ;
+	       numbytes++ ;
+	    }
+	    post = (char *)malloc(numbytes+1);
 	    r = post ;
-	    while(*p != '}')
+	    for (j=0; j < numbytes; j++)
 	       *r++ = *p++;
 	    *r = 0;
 	 }



More information about the tex-k mailing list