[Snort-devel] snort-1.9: Check for chrootdir before access(pv.log_dir)

Matthew Callaway matt at ...806...
Sun Oct 20 06:56:04 EDT 2002


This is a more appropriate patch for what I'm getting at.  It also
doesn't segfault.  ;)


Matt

--- snort.c.orig        Wed Sep 25 14:56:53 2002
+++ snort.c     Fri Oct 18 11:40:04 2002
@@ -1007,10 +1007,36 @@
                 break;

             case 'l':                /* use log dir <X> */
+                /* Test for chroot first, note that order matters
+                 * in specifying command line args */
                 strlcpy(pv.log_dir, optarg, STD_BUF);
+                if (strlen(chrootdir))
+                {
+                    int len;
+                    char *temp;
+
+                    len = strlen(chrootdir) + strlen(pv.log_dir) + 1;
+                    if (len > STD_BUF) {
+                        FatalError("pv.log_dir is not big enough to hold chrootdir + pv.log_dir");
+                    }
+
+                    temp = strdup(pv.log_dir);
+                    strcpy(pv.log_dir, chrootdir);
+                    strcat(pv.log_dir, temp);
+
+                    if( access(pv.log_dir, 2) != 0 )
+                    {
+                        FatalError("ERROR: log directory '%s' does not exist\n", pv.log_dir);
+                    }
+                    strcpy(pv.log_dir,temp);
+                    free(temp);
+                }
+                else
+                {
                 if( access(pv.log_dir, 2) != 0 )
                 {
                     FatalError("ERROR: log directory '%s' does not exist\n", pv.log_dir);
+                    }
                 }
                 pv.log_flag = 1;
                 break;





More information about the Snort-devel mailing list