Package: jesred
Version: 1.2pl1-8
Severity: wishlist

here is a patch to improve extended regex mathing on patterns which does
not contains `()' chars. IMHO it need to notice the users, that the jesred
doing `basic' regex matching if it does not count a special  `*', `+',
`?', or bound chars. I added a code to do an extended pattern matching
if REG consists of that (unescaped) chars, and semantic changes to
compile it without warnings :)


-- System Information:
Debian Release: 3.1
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.4.27
Locale: LANG=C, LC_CTYPE=C

Versions of packages jesred depends on:
ii  libc6                       2.3.2.ds1-22 GNU C Library: Shared libraries an
hi  squid                       2.5.10-5     Internet Object Cache (WWW proxy c

-- no debconf information
diff -rNu jesred-1.2pl1.orig/Makefile jesred-1.2pl1/Makefile
--- jesred-1.2pl1.orig/Makefile 2005-09-15 21:50:09.000000000 +0400
+++ jesred-1.2pl1/Makefile      2005-09-15 21:46:14.000000000 +0400
@@ -13,7 +13,7 @@
 #AC_CFLAGS       = -xO5 -mr -s -xcrossfile #-g -xsb            # SUN cc >= 4.0
 #AC_CFLAGS     = -O3 -s                                # SGI cc, AIX cc
 #AC_CFLAGS     = -O5 -s                                # GNU cc
-AC_CFLAGS      = -O3 -g -DLINUX -Wall
+AC_CFLAGS      = -O3 -DLINUX -Wall
 #AC_CFLAGS     = -O3 -g -pg -DLINUX -Wall
 
 # extra Libraries ( we need this for inet_addr(char *) only )
@@ -53,7 +53,7 @@
 # If jesred is compiled without -DUSE_ACCEL the ACCEL strings in the
 # redirect rules are ignored, if there are some.
 # 
-#DEFS = -DUSE_ACCEL
+DEFS = -DUSE_ACCEL
 
 # That's it - no further changes should be necessary ;-)
 # ===========================================================================
diff -rNu jesred-1.2pl1.orig/config.c jesred-1.2pl1/config.c
--- jesred-1.2pl1.orig/config.c 2005-09-15 21:50:09.000000000 +0400
+++ jesred-1.2pl1/config.c      2005-09-15 20:30:14.000000000 +0400
@@ -58,13 +58,13 @@
     fd = fopen(*file, "r");
     if(fd == NULL) {
        token = strerror(errno);
-       log(ERROR, "unable to open local addresses file %s: %s\n",
+       printlog(ERROR, "unable to open local addresses file %s: %s\n",
            *file ? *file : "", token);
        echo_mode = 1;
        return;
     }
     
-    log(INFO, "Loading IP List from %s\n",*file);
+    printlog(INFO, "Loading IP List from %s\n",*file);
     while( !echo_mode && (fgets(buff, BUFSIZE, fd) != NULL) ) {
        token = CleanLine(buff);
        if ( token == NULL )
@@ -177,11 +177,11 @@
     if ( ! *file || (fd = fopen(*file, "rt")) == NULL ) {
        echo_mode = 1;
        token = strerror(errno);
-       log(ERROR, "unable to open redirect patterns file %s: %s\n",
+       printlog(ERROR, "unable to open redirect patterns file %s: %s\n",
            *file ? *file : "", token);
        return;
     }
-    log(INFO, "Reading Patterns from config %s\n", *file);
+    printlog(INFO, "Reading Patterns from config %s\n", *file);
     
     while(!echo_mode && (fgets(buff, BUFSIZE, fd) != NULL)) {
        
diff -rNu jesred-1.2pl1.orig/debian/changelog jesred-1.2pl1/debian/changelog
--- jesred-1.2pl1.orig/debian/changelog 2005-09-15 21:50:09.000000000 +0400
+++ jesred-1.2pl1/debian/changelog      2005-09-15 20:37:10.000000000 +0400
@@ -1,3 +1,10 @@
+jesred (1.2pl1-9) unstable; urgency=low
+
+  * changed extended regex detection to reflect of `+?[{|'
+    chars in match pattern
+
+ -- Alexander Davydenko <[EMAIL PROTECTED]>  Thu, 15 Sep 2005 20:36:49 +0400
+
 jesred (1.2pl1-8) unstable; urgency=low
 
   * updated zed's comments in the example bofh rule file (closes: #263774)
diff -rNu jesred-1.2pl1.orig/ip_list.c jesred-1.2pl1/ip_list.c
--- jesred-1.2pl1.orig/ip_list.c        2005-09-15 21:50:09.000000000 +0400
+++ jesred-1.2pl1/ip_list.c     2005-09-15 20:30:14.000000000 +0400
@@ -136,17 +136,17 @@
 
 #ifdef DEBUG
     if (!list) {
-       log(DEBG, "ACL: denied %s\n", inet_ntoa(address));
+       printlog(DEBG, "ACL: denied %s\n", inet_ntoa(address));
        return IP_DENY;
     }
     for (p = list; p; p = p->next) {
        if (ip_acl_match(address, p)) {
-           log(DEBG, "ACL: %s %s\n", p->access==IP_DENY ? "denied" : "allowed",
+           printlog(DEBG, "ACL: %s %s\n", p->access==IP_DENY ? "denied" : 
"allowed",
                inet_ntoa(address));
            return p->access;
        }
     }
-    log(DEBG, "ACL: denied %s\n", inet_ntoa(address));
+    printlog(DEBG, "ACL: denied %s\n", inet_ntoa(address));
     return IP_DENY;
 #else
     if (!list)
@@ -194,7 +194,7 @@
     a1 = a2 = a3 = a4 = 0;
     c = sscanf(ip_str, "%d.%d.%d.%d/%d", &a1, &a2, &a3, &a4, &m1);
     if (m1 < 0 || m1 > 32) {
-       log(ERROR, "addToIPACL: Ignoring invalid IP acl line '%s'\n",
+       printlog(ERROR, "addToIPACL: Ignoring invalid IP acl line '%s'\n",
              ip_str);
        return;
     }
diff -rNu jesred-1.2pl1.orig/log.c jesred-1.2pl1/log.c
--- jesred-1.2pl1.orig/log.c    1998-05-17 19:24:54.000000000 +0400
+++ jesred-1.2pl1/log.c 2005-09-15 20:30:13.000000000 +0400
@@ -63,7 +63,7 @@
 }
 
 void
-log(log_code c, char *format, ...) {
+printlog(log_code c, char *format, ...) {
     FILE *fd;
     
     char msg[BUFSIZE];
diff -rNu jesred-1.2pl1.orig/log.h jesred-1.2pl1/log.h
--- jesred-1.2pl1.orig/log.h    1998-05-17 19:25:08.000000000 +0400
+++ jesred-1.2pl1/log.h 2005-09-15 20:30:13.000000000 +0400
@@ -30,7 +30,7 @@
     INFO
 } log_code;
 
-extern void log(log_code c, char *format, ...);
+extern void printlog(log_code c, char *format, ...);
 extern void closeLogs(void);
 extern void openLogs(char **, char **);
 
diff -rNu jesred-1.2pl1.orig/main.c jesred-1.2pl1/main.c
--- jesred-1.2pl1.orig/main.c   2005-09-15 21:50:09.000000000 +0400
+++ jesred-1.2pl1/main.c        2005-09-15 20:30:13.000000000 +0400
@@ -96,7 +96,7 @@
        int val;
        
        sig_hup = 0;
-       log(INFO, "Freeing up old linked lists\n");
+       printlog(INFO, "Freeing up old linked lists\n");
        ip_acl_destroy(&ip_list);
        plist_destroy(&pattern_list);
        closeLogs();
@@ -107,8 +107,8 @@
        read_rules(&f_rules, &pattern_list);
        
        if(echo_mode)
-           log(ERROR, "Invalid condition - continuing in ECHO mode\n");
-       log(INFO, "%s (PID %d) started\n", APPNAME, (int)getpid());
+           printlog(ERROR, "Invalid condition - continuing in ECHO mode\n");
+       printlog(INFO, "%s (PID %d) started\n", APPNAME, (int)getpid());
        
        while((!sig_hup) && (fgets(buff, BUFSIZE, stdin) != NULL)){
            if(echo_mode) {
@@ -129,7 +129,7 @@
            if(echo_mode) {
                puts("");
                fflush(stdout);
-               log(ERROR, "Invalid condition - continuing in ECHO mode\n");
+               printlog(ERROR, "Invalid condition - continuing in ECHO 
mode\n");
                continue;
            }
            /* find a rule for rewriting the URL */
@@ -151,7 +151,7 @@
                    printf("%s %s %s %s\n",
                           redirect_url, src_addr, ident, method);
                    fflush(stdout);
-                   log(MATCH, "%s %s %s %d\n", src_addr, url, redirect_url,
+                   printlog(MATCH, "%s %s %s %d\n", src_addr, url, 
redirect_url,
                        val);
                }
            }
diff -rNu jesred-1.2pl1.orig/pattern_list.c jesred-1.2pl1/pattern_list.c
--- jesred-1.2pl1.orig/pattern_list.c   2005-09-15 21:50:09.000000000 +0400
+++ jesred-1.2pl1/pattern_list.c        2005-09-15 21:30:59.000000000 +0400
@@ -64,6 +64,7 @@
     int abort_type = 0;
     int parenthesis;
     int stored;
+    char *pointer, *ptemp;
     
     /*  The regex_flags that we use are:
        REG_EXTENDED 
@@ -80,7 +81,7 @@
     stored = sscanf(pattern, "%s %s %s", type, first, second);
 #endif
     if((stored < 2) || (stored > 4)) {
-       log(ERROR, "unable to get a pair of patterns in add_to_patterns() "
+       printlog(ERROR, "unable to get a pair of patterns in add_to_patterns() "
            "for [%s]\n", pattern);
        echo_mode = 1;
        return;
@@ -104,7 +105,7 @@
        if (parenthesis < 0) {      
            /* The function returned an invalid result,
               indicating an invalid string */
-           log (ERROR, "count_parenthesis() returned "
+           printlog (ERROR, "count_parenthesis() returned "
                 "left count did not match right count for line: [%s]\n",
                 pattern);
            echo_mode = 1;
@@ -116,23 +117,41 @@
            regex_flags ^= REG_NOSUB;
        }
     }
-  
+    /*** BUG: it must use extended regex if `first' consists
+     *        of extended pattern chars `+?{|'
+     */
+    if (rpattern.type != EXTENDED) {
+       pointer = first;
+       while (pointer != NULL) {
+           /* first special char breaks extended regex */
+           if ((ptemp = strpbrk(pointer, "+?{")) == NULL || ptemp == pointer)
+               break;
+           if (*(ptemp-1) != '\\') {
+               regex_flags |= REG_EXTENDED;
+               rpattern.type = EXTENDED;
+               regex_flags ^= REG_NOSUB;
+               break;
+           }
+           pointer = *(++ptemp) == '\0' ? NULL : ptemp;
+       }
+    }
+    
     if(regcomp(&compiled, first, regex_flags)) {
-       log(ERROR, "Invalid regex [%s] in pattern file\n", first);
+       printlog(ERROR, "Invalid regex [%s] in pattern file\n", first);
        echo_mode = 1;
        return;
     }
     rpattern.cpattern = compiled;
     rpattern.pattern = (char *)malloc(sizeof(char) * (strlen(first) +1));
     if(rpattern.pattern == NULL) {
-       log(ERROR, "unable to allocate memory in add_to_patterns()\n");
+       printlog(ERROR, "unable to allocate memory in add_to_patterns()\n");
        echo_mode = 1;
        return;
     }
     strcpy(rpattern.pattern, first);
     rpattern.replacement = (char *)malloc(sizeof(char) * (strlen(second) +1));
     if(rpattern.replacement == NULL) {
-       log(ERROR, "unable to allocate memory in add_to_patterns()\n");
+       printlog(ERROR, "unable to allocate memory in add_to_patterns()\n");
        echo_mode = 1;
        return;
     }
@@ -145,7 +164,7 @@
        rpattern.accel = get_accel(accel, &rpattern.accel_type, 
                                   rpattern.case_sensitive);
        if(rpattern.accel == NULL) {
-           log(ERROR, "unable to allocate memory from get_accel()\n");
+           printlog(ERROR, "unable to allocate memory from get_accel()\n");
            echo_mode = 1;
            return;
        }
@@ -238,7 +257,7 @@
        curr->next = new;
     }
     if(! new) {
-       log(ERROR, "unable to allocate memory in add_to_plist()\n");
+       printlog(ERROR, "unable to allocate memory in add_to_plist()\n");
        /* exit(3); */
        echo_mode = 1;
        return;
diff -rNu jesred-1.2pl1.orig/rewrite.c jesred-1.2pl1/rewrite.c
--- jesred-1.2pl1.orig/rewrite.c        2005-09-15 21:50:09.000000000 +0400
+++ jesred-1.2pl1/rewrite.c     2005-09-15 20:30:13.000000000 +0400
@@ -102,11 +102,11 @@
            if ( end[i] )
                *end[i] = ' ';
        }
-       log(ERROR, "incorrect input (%d): %s", c, buff);
+       printlog(ERROR, "incorrect input (%d): %s", c, buff);
        return 1;
     }
 #ifdef DEBUG
-    log(DEBG, "Request: %s %s %s %s\n", *url, *src_addr, *ident, *method);
+    printlog(DEBG, "Request: %s %s %s %s\n", *url, *src_addr, *ident, *method);
 #endif    
     
     /* all methods must be GET or ICP_QUERY */
@@ -121,14 +121,14 @@
            if ( end[c] )
                *end[c] = ' ';
        }
-       log(DEBG, "method not \"GET\" %s\n", buff);
+       printlog(DEBG, "method not \"GET\" %s\n", buff);
 #endif 
        return 1;
     }
            
     /* URL with less than 7 char is invalid */
     if(strlen(*url) <= 7) {
-       log(ERROR, "strlen url to short (%d)\n", strlen(*url));
+       printlog(ERROR, "strlen url to short (%d)\n", strlen(*url));
        return 1;
     }
 
@@ -141,7 +141,7 @@
        it is already loaded, when squid runs - so not much waste of
        memory ;-) */
     if ( (address.s_addr = inet_addr(*src_addr)) == -1 ) {
-       log(ERROR, "client IP address not valid %s\n",
+       printlog(ERROR, "client IP address not valid %s\n",
            *src_addr ? *src_addr : "");
        if ( token )
            *token = '/';
@@ -153,7 +153,7 @@
     /* make sure the IP source address matches that of the ones in our list */
     if( ip_access_check(address, ip) == IP_DENY ) {
 #ifdef DEBUG
-       log(DEBG, "client IP address %s not matched\n", *src_addr);
+       printlog(DEBG, "client IP address %s not matched\n", *src_addr);
 #endif  
        return 1;
     }
@@ -190,7 +190,7 @@
            }
            if(matched) {
 #ifdef DEBUG
-               log(DEBG, "abort pattern matched: %s (rule %d)\n",
+               printlog(DEBG, "abort pattern matched: %s (rule %d)\n",
                    url, pattern_no);
 #endif         
                return (0 - pattern_no); /* URL matches abort file extension */
@@ -206,7 +206,7 @@
                               curr->accel_type, 
                               curr->case_sensitive)) {
 #ifdef DEBUG
-                   log(DEBG, "URL %s matches accelerator %s (rule %d)\n",
+                   printlog(DEBG, "URL %s matches accelerator %s (rule %d)\n",
                        url, curr->accel, pattern_no);
 #endif             
                    /* Now we must test for normal or extended */
diff -rNu jesred-1.2pl1.orig/util.c jesred-1.2pl1/util.c
--- jesred-1.2pl1.orig/util.c   1998-05-17 19:27:29.000000000 +0400
+++ jesred-1.2pl1/util.c        2005-09-15 20:44:51.000000000 +0400
@@ -100,6 +100,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <signal.h>
+#include <string.h>
 
 #include "util.h"
 #include "log.h"
@@ -109,7 +110,7 @@
 HUPhandler(int kill)
 {
     sig_hup = 1;
-    log(ERROR, "HUP received.  Reconfiguring....\n");
+    printlog(ERROR, "HUP received.  Reconfiguring....\n");
     signal(SIGHUP, HUPhandler);
 }
 
@@ -117,7 +118,7 @@
 KILLhandler(int kill)
 {
     sig_hup = 1;
-    log(ERROR, "KILL received.  Shutting down....\n");
+    printlog(ERROR, "KILL received.  Shutting down....\n");
     closeLogs();
     exit(1);
 }
@@ -150,7 +151,7 @@
         save = (char *)malloc(strlen(str) + 1);
         if ( save == NULL ) {
             perror("Problems allocating memory for a string:");
-            log(ERROR,"Problems allocating memory for \"%s\"",str);
+            printlog(ERROR,"Problems allocating memory for \"%s\"",str);
         }
         else {
             strcpy(save, str);

Reply via email to