lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev [PATCH][pre1] fix lossage in LYTraversal.c


From: John Bley
Subject: lynx-dev [PATCH][pre1] fix lossage in LYTraversal.c
Date: Fri, 7 May 1999 16:37:57 -0400 (EDT)

* Fix some serious lossage in lookup_reject (LYTraversal.c): memory and 
  logic errors.  This (replaced) line is one for the record books:
      frag = strlen(buffer) - 1; /* real length, minus trailing null */
  What was this guy smoking?  (John Bley)

Previously, this code caused a read before an array boundary as well as 
failing to compare the right number of characters in a pattern.  
Hopefully I've fixed that but I'll revisit this function when I stop 
laughing at that comment.

-- 
John Bley - address@hidden
Duke '99 - English/Computer Science
  Since English is a mess, it maps well onto the problem space,
  which is also a mess, which we call reality.     - Larry Wall

diff -Burp lynx2-8-2/src/LYTraversal.c lynx2-8-2-patched/src/LYTraversal.c
--- lynx2-8-2/src/LYTraversal.c Tue Apr 27 08:59:06 1999
+++ lynx2-8-2-patched/src/LYTraversal.c Fri May  7 16:29:07 1999
@@ -142,7 +142,7 @@ PUBLIC BOOLEAN lookup_reject ARGS1(char 
     char *buffer = NULL;
     char *line = NULL;
     char ch;
-    int  frag;
+    int len;
     int result = FALSE;
 
     if ((ifp = fopen(TRAVERSE_REJECT_FILE,"r")) == NULL){
@@ -152,20 +152,21 @@ PUBLIC BOOLEAN lookup_reject ARGS1(char 
     HTSprintf0(&line, "%s\n", target);
 
     while (LYSafeGets(&buffer, ifp) != NULL && !result) {
-       frag = strlen(buffer) - 1; /* real length, minus trailing null */
-       ch   = buffer[frag - 1];   /* last character in buffer */
-       if (frag > 0) {            /* if not an empty line */
+       len = strlen(buffer); 
+       if (len)  ch = buffer[len - 1];   /* last character in buffer */
+       if (len > 0) {     /* if not an empty line */
            if (ch == '*') {
-               if (frag == 1 || ((strncmp(line,buffer,frag - 1)) == 0)) {
+               /* if last char is * and the rest of the chars match */
+               if ((len == 1) || (strncmp(line,buffer,len - 1) == 0)) {
                    result = TRUE;
                }
-           } else { /* last character = "*" test */
+           } else {
                if (STREQ(line,buffer)) {
                    result = TRUE;
                }
-           } /* last character = "*" test */
-       } /* frag >= 0 */
-    } /* end while */
+           }
+       }
+    } /* end while loop over the file */
     FREE(buffer);
     FREE(line);
 

reply via email to

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