nmh-commits
[Top][All Lists]
Advanced

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

[Nmh-commits] nmh/uip picksbr.c


From: Paul Fox
Subject: [Nmh-commits] nmh/uip picksbr.c
Date: Sat, 22 Apr 2006 16:33:48 +0000

CVSROOT:        /sources/nmh
Module name:    nmh
Branch:         
Changes by:     Paul Fox <address@hidden>       06/04/22 16:33:48

Modified files:
        uip            : picksbr.c 

Log message:
        fixes case where a very long character-class range (128 or
        more characters) causes negative indexing into pattern string.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/picksbr.c.diff?tr1=1.10&tr2=1.11&r1=text&r2=text

Patches:
Index: nmh/uip/picksbr.c
diff -u nmh/uip/picksbr.c:1.10 nmh/uip/picksbr.c:1.11
--- nmh/uip/picksbr.c:1.10      Fri Mar 31 15:14:49 2006
+++ nmh/uip/picksbr.c   Sat Apr 22 16:33:48 2006
@@ -2,7 +2,7 @@
 /*
  * picksbr.c -- routines to help pick along...
  *
- * $Id: picksbr.c,v 1.10 2006/03/31 15:14:49 pgf Exp $
+ * $Id: picksbr.c,v 1.11 2006/04/22 16:33:48 pgf Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -575,7 +575,7 @@
 {
     register int c;
     int cclcnt;
-    register char *ep, *dp, *sp, *lastep = 0;
+    register unsigned char *ep, *dp, *sp, *lastep = 0;
 
     dp = (ep = n->n_expbuf) + sizeof n->n_expbuf;
     sp = astr;
@@ -614,7 +614,7 @@
            case '[': 
                *ep++ = CCL;
                *ep++ = 0;
-               cclcnt = 1;
+               cclcnt = 0;
                if ((c = *sp++) == '^') {
                    c = *sp++;
                    ep[-2] = NCCL;
@@ -639,6 +639,8 @@
                            goto cerror;
                    }
                } while ((c = *sp++) != ']');
+               if (cclcnt > 255)
+                   goto cerror;
                lastep[1] = cclcnt;
                continue;
 
@@ -744,14 +746,14 @@
 static int
 advance (char *alp, char *aep)
 {
-    register char *lp, *ep, *curlp;
+    register unsigned char *lp, *ep, *curlp;
 
-    lp = alp;
-    ep = aep;
+    lp = (unsigned char *)alp;
+    ep = (unsigned char *)aep;
     for (;;)
        switch (*ep++) {
            case CCHR: 
-               if (*ep++ == *lp++ || ep[-1] == cc[(unsigned char)lp[-1]])
+               if (*ep++ == *lp++ || ep[-1] == cc[lp[-1]])
                    continue;
                return 0;
 
@@ -770,14 +772,14 @@
 
            case CCL: 
                if (cclass (ep, *lp++, 1)) {
-                   ep += *ep;
+                   ep += *ep + 1;
                    continue;
                }
                return 0;
 
            case NCCL: 
                if (cclass (ep, *lp++, 0)) {
-                   ep += *ep;
+                   ep += *ep + 1;
                    continue;
                }
                return 0;
@@ -790,7 +792,7 @@
 
            case CCHR | STAR: 
                curlp = lp;
-               while (*lp++ == *ep || cc[(unsigned char)lp[-1]] == *ep)
+               while (*lp++ == *ep || cc[lp[-1]] == *ep)
                    continue;
                ep++;
                goto star;
@@ -800,7 +802,7 @@
                curlp = lp;
                while (cclass (ep, *lp++, ep[-1] == (CCL | STAR)))
                    continue;
-               ep += *ep;
+               ep += *ep + 1;
                goto star;
 
        star: 
@@ -819,19 +821,18 @@
 
 
 static int
-cclass (char *aset, int ac, int af)
+cclass (unsigned char *aset, int ac, int af)
 {
-    register int    n;
-    register char   c,
-                   *set;
+    register unsigned int    n;
+    register unsigned char   c, *set;
 
     set = aset;
     if ((c = ac) == 0)
        return (0);
 
     n = *set++;
-    while (--n)
-       if (*set++ == c || set[-1] == cc[(unsigned char)c])
+    while (n--)
+       if (*set++ == c || set[-1] == cc[c])
            return (af);
 
     return (!af);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]