[Snort-devel] Suspect bug in mstring.c

gangadhar npk npkg at ...1093...
Wed Jan 30 00:39:08 EST 2002


Hello everyone,

             We wish to know the 'exact' purpose of the function 
mSplit() in the file mstring.c. As the comment states ...


> /****************************************************************
>  *
>  *  Function: mSplit()
>  *
>  *  Purpose: Splits a string into tokens non-destructively.
>  *
>  *  Parameters:
>  *      char *str => the string to be split
>  *      char *sep => a string of token seperaters
>  *      int max_strs => how many tokens should be returned
>  *      int *toks => place to store the number of tokens found in str
>  *      char meta => the "escape metacharacter", treat the character
>  *                   after this character as a literal and "escape" a
>  *                   seperator
>  *
>  *  Returns:
>  *      2D char array with one token per "row" of the returned
>  *      array.
>  *
>  ****************************************************************/

The string *str , is seperated based on the token seperator *sep. Is the 
seperator a single character or can it be more ?
    If the strlen(sep) > 1 , then there seems to be a problem in the 
functioning.


// From the function mSplit ()


     /* loop thru each letter in the string being tokenized */
     while(idx < end)
     {
         /* loop thru each seperator string char */
         while(sep_idx < sep_end)
         {
             /*
              * if the current string-indexed char matches the current
              * seperator char...
              */


/*=====================================================================*/
/* ERRATA : Every character (*idx) of the string (str) is compared with 
the first character (*sep_idx)  of the seperator (sep). And if they are 
equal then the token picked up by (idx -len ) is stored in the returning 
array (retstr). i.e only the presence of the  first character of the 
seperator is checked for equality . Remainig characters of the 
seperator(if any) are not checked before the token is actually stored .
For example :
    if the string is --> The*{}quick*{}fox*jumps*{}over*the*{}lazy*dog
    the seperator is --> *{}
     max_strs        --> 5
    the o/p should be :-
            The
            quick
            fox*jumps
            over*the
            lazy dog
  But, the O/P is :
            The
            quick
            fox
            jumps
            {}over*the*{}lazy*dog


   Please check it up.

*/



  If we are wrong please do let us know. The code for this function has 
been attache in a file mstring1.c

                          Bye
                                 Sunil    & Gangadhar





-- 
"Software is like sex: it's better when it's free"
                      - Linus
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mstring1.c
URL: <https://lists.snort.org/pipermail/snort-devel/attachments/20020130/ee356682/attachment.c>


More information about the Snort-devel mailing list