Snort mailing list archives

Replace calls index() <deprecated> with strchr() in Snort 2.9.5


From: Bill Parker <wp02855 () gmail com>
Date: Fri, 19 Jul 2013 12:08:22 -0700

Hello All,

In reviewing various files in Snort-2.9.5, I found a number
of instances where index() <deprecated> was used, and the patch
files below replace calls to index() with strchr() <ANSI/ISO>.

In directory 'snort-2.9.5/src/detection-plugins', file
'sp_ip_tos_check.c', the following patch file replaces
calls to index() with strchr():

--- sp_ip_tos_check.c.orig      2013-07-18 12:27:51.397883953 -0700
+++ sp_ip_tos_check.c   2013-07-18 12:28:32.473881887 -0700
@@ -200,7 +200,7 @@
         start = &data[0];
     }

-    if(index(start, (int) 'x') == NULL && index(start, (int)'X') == NULL)
+    if(strchr(start, (int) 'x') == NULL && strchr(start, (int)'X') == NULL)
     {
         ds_ptr->ip_tos = (uint8_t)SnortStrtoulRange(start, &endTok, 10, 0,
UINT8_MAX);
         if ((endTok == start) || (*endTok != '\0'))
@@ -212,10 +212,10 @@
     else
     {
         /* hex? */
-        start = index(data,(int)'x');
+        start = strchr(data,(int)'x');
         if(!start)
         {
-            start = index(data,(int)'X');
+            start = strchr(data,(int)'X');
         }
         if (start)
         {

In directory 'snort-2.9.5/src/detection-plugins', file
'sp_pattern_match.c', the following patch file replaces
calls to index() with strchr() <this also contains a
previous patch for converting bzero() calls to memset()>:

--- sp_pattern_match.c.orig     2013-07-18 08:43:44.369888130 -0700
+++ sp_pattern_match.c  2013-07-18 12:33:24.026883058 -0700
@@ -1324,21 +1324,21 @@
     char *quote_one = NULL, *quote_two = NULL;
     char *comma = NULL;

-    quote_one = index(data, '"');
+    quote_one = strchr(data, '"');
     if (quote_one)
     {
-        quote_two = index(quote_one+1, '"');
+        quote_two = strchr(quote_one+1, '"');
         while ( quote_two && quote_two[-1] == '\\' )
-            quote_two = index(quote_two+1, '"');
+            quote_two = strchr(quote_two+1, '"');
     }

     if (quote_one && quote_two)
     {
-        comma = index(quote_two, ',');
+        comma = strchr(quote_two, ',');
     }
     else if (!quote_one)
     {
-        comma = index(data, ',');
+        comma = strchr(data, ',');
     }

     if (comma)
@@ -1471,7 +1471,7 @@
     PatternMatchData *ds_idx;

     /* clear out the temp buffer */
-    bzero(tmp_buf, MAX_PATTERN_SIZE);
+    memset(tmp_buf, '\0', MAX_PATTERN_SIZE);

     if (rule == NULL)
         ParseError("ParsePattern Got Null enclosed in quotation marks
(\")!");
@@ -1486,7 +1486,7 @@
     }

     /* find the start of the data */
-    start_ptr = index(rule, '"');
+    start_ptr = strchr(rule, '"');

     if (start_ptr != rule)
         ParseError("Content data needs to be enclosed in quotation marks
(\")!");
@@ -1530,8 +1530,7 @@
     dummy_end = (dummy_idx + size);

     /* why is this buffer so small? */
-    bzero(hex_buf, 3);
-    memset(hex_buf, '0', 2);
+    memset(hex_buf, '\0', 3);

     /* BEGIN BAD JUJU..... */
     while(idx < end_ptr)
@@ -1640,8 +1639,7 @@
                                     strtol(hex_buf, (char **) NULL,
16)&0xFF;

                                 dummy_size++;
-                                bzero(hex_buf, 3);
-                                memset(hex_buf, '0', 2);
+                                memset(hex_buf, '\0', 3);
                             }
                             else
                             {
@@ -2486,7 +2484,7 @@
         data++;

     /* grab everything between the starting " and the end one */
-    sptr = index(data, '"');
+    sptr = strchr(data, '"');
     eptr = strrchr(data, '"');

     if(sptr != NULL && eptr != NULL)
@@ -2545,8 +2543,8 @@
     }

     /* clear the line and rule buffers */
-    bzero((char *) buf, STD_BUF);
-    bzero((char *) rule_buf, STD_BUF);
+    memset((char *) buf, '\0', STD_BUF);
+    memset((char *) rule_buf, '\0', STD_BUF);
     frazes_count = 0;

     /* loop thru each list_file line and content to the rule */

In directory 'snort-2.9.5/src/detection-plugins', file
'sp_tcp_win_check.c', the following patch file replaces
calls to index() with strchr():

--- sp_tcp_win_check.c.orig     2013-07-18 12:36:11.167880131 -0700
+++ sp_tcp_win_check.c  2013-07-18 12:36:49.028881611 -0700
@@ -205,7 +205,7 @@
         start = &data[0];
     }

-    if(index(start, (int) 'x') == NULL && index(start, (int)'X') == NULL)
+    if(strchr(start, (int) 'x') == NULL && strchr(start, (int)'X') == NULL)
     {
         win_size = SnortStrtolRange(start, &endTok, 10, 0, UINT16_MAX);
         if ((endTok == start) || (*endTok != '\0'))
@@ -217,10 +217,10 @@
     else
     {
         /* hex? */
-        start = index(data,(int)'x');
+        start = strchr(data,(int)'x');
         if(!start)
         {
-            start = index(data,(int)'X');
+            start = strchr(data,(int)'X');
         }
         if (start)
         {

In directory 'snort-2.9.5/src/detection-plugins', file
'sp_replace.c', the following patch file replaces calls
to index() with strchr() <this also contains a previous
patch for converting bzero() calls to memset()>:

--- sp_replace.c.orig   2013-07-18 08:48:41.818893728 -0700
+++ sp_replace.c        2013-07-18 12:38:44.570878841 -0700
@@ -111,7 +111,7 @@
             file_name, file_line);
     }
     /* clear out the temp buffer */
-    bzero(tmp_buf, MAX_PATTERN_SIZE);
+    memset(tmp_buf, '\0', MAX_PATTERN_SIZE);

     while(isspace((int)*rule))
         rule++;
@@ -122,7 +122,7 @@
     }

     /* find the start of the data */
-    start_ptr = index(rule, '"');
+    start_ptr = strchr(rule, '"');

     if(start_ptr == NULL)
     {
@@ -163,8 +163,7 @@
     dummy_end = (dummy_idx + size);

     /* why is this buffer so small? */
-    bzero(hex_buf, 3);
-    memset(hex_buf, '0', 2);
+    memset(hex_buf, '\0', 3);

     /* BEGIN BAD JUJU..... */
     while(idx < end_ptr)
@@ -269,8 +268,7 @@
                                     strtol(hex_buf, (char **) NULL,
16)&0xFF;

                                 dummy_size++;
-                                bzero(hex_buf, 3);
-                                memset(hex_buf, '0', 2);
+                                memset(hex_buf, '\0', 3);
                             }
                             else
                             {


In directory 'snort-2.9.5/src/dynamic-preprocessors/sdf',
file  'sdf_pattern_match.c', the following patch file
replaces calls to index() with strchr():

--- sdf_pattern_match.c.orig    2013-07-18 12:40:51.368879507 -0700
+++ sdf_pattern_match.c 2013-07-18 12:41:17.518883291 -0700
@@ -82,7 +82,7 @@
         return;

     /* Locate first '{' */
-    bracket_index = index(*pii, '{');
+    bracket_index = strchr(*pii, '{');

     /* Brackets at the beginning have nothing to modify. */
     if (bracket_index == *pii)
@@ -97,7 +97,7 @@
         /* Ignore escaped brackets */
         if ((bracket_index > *pii) && (*(bracket_index-1) == '\\'))
         {
-            bracket_index = index(bracket_index+1, '{');
+            bracket_index = strchr(bracket_index+1, '{');
             continue;
         }

@@ -133,7 +133,7 @@
         num_brackets++;

         /* Next bracket */
-        bracket_index = index(bracket_index+1, '{');
+        bracket_index = strchr(bracket_index+1, '{');
     }

     /* By this point, the brackets all match up. */


In directory 'snort-2.9.5/src/dynamic-preprocessors/ftptelnet',
file 'pp_ftp.c', the following patch file replaces calls to
index() with strchr():

--- pp_ftp.c.orig       2013-07-18 12:44:46.451880548 -0700
+++ pp_ftp.c    2013-07-18 12:45:04.336881624 -0700
@@ -358,7 +358,7 @@
         strncpy(buf, tok, len);
         buf[len] = '\0';
     }
-    s = index(buf, delim);
+    s = strchr(buf, delim);

     if ( s ) *s = '\0';
     else *buf = '\0';
@@ -414,7 +414,7 @@
                 break;
         }
         /* advance to next field */
-        tok = index(tok, delim);
+        tok = strchr(tok, delim);
         field++;
     }

In directory 'snort-2.9.5/src/dynamic-preprocessors/ftptelnet',
file 'snort_ftptelnet.c', the following patch file replaces
calls to index() with strchr():

--- snort_ftptelnet.c.orig      2013-07-18 12:45:48.489881388 -0700
+++ snort_ftptelnet.c   2013-07-18 12:46:03.974880469 -0700
@@ -1915,7 +1915,7 @@
     }
     else if ( *fmt == *F_LITERAL )
     {
-        char* end = index(++fmt, *F_LITERAL);
+        char* end = strchr(++fmt, *F_LITERAL);
         int len = end ? end - fmt : 0;

         if ( len < 1 )

A 'make' and 'make install' results in a clean compile and
installation of the above patch files for Snort-2.9.5

Here is a listing of the files in the archive:

Archive:  index-patches.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      775  07-18-2013 12:32   sp_ip_tos_check.c.patch
     2597  07-18-2013 12:35   sp_pattern_match.c.patch
      762  07-18-2013 12:38   sp_tcp_win_check.c.patch
      900  07-18-2013 12:43   sdf_pattern_match.c.patch
      484  07-18-2013 12:47   pp_ftp.c.patch
      354  07-18-2013 12:46   snort_ftptelnet.c.patch
     1003  07-18-2013 08:50   sp_replace.c.patch
---------                     -------
     6875                     7 files

I am attaching the patch files (as a zip archive) to
this e-mail

Bill Parker (wp02855 at gmail dot com)

Attachment: index-patches.zip
Description:

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Snort-devel mailing list
Snort-devel () lists sourceforge net
https://lists.sourceforge.net/lists/listinfo/snort-devel
Archive:
http://sourceforge.net/mailarchive/forum.php?forum_name=snort-devel

Please visit http://blog.snort.org for the latest news about Snort!

Current thread: