|
|||||||||||
|
[Snort-devel] patch for sp_pattern_match.c::ParsePattern (BAD JUJU)
From: Pavel Zeldin <pavel.zeldin(at)idt.com>
Date: Fri Sep 26 2003 - 19:46:10 EDT
The patch is against snort-2.0.2
Pavel.
/****************************************************************************+ * even swears in ParsePattern() terms. + ***************************************************************************/ +typedef struct _ByteBuffer +{ + u_int8_t *buf_start; /*< start of the buffer */ + u_int8_t *buf_current_pos; /*< where next insertion goes */ + u_int8_t *buf_end; /*< one past last byte of the buffer */ +} ByteBuffer; + + +static ByteBuffer ByteBufferInit(u_int8_t *store, unsigned long buf_size) +{ + ByteBuffer buf; + buf.buf_start = buf.buf_end = buf.buf_current_pos = store; + buf.buf_end += buf_size; + memset(store, 0, buf_size); + return buf; +} + + +static void ByteBufferAppend(ByteBuffer *buf, u_int8_t octet) +{ + if(buf->buf_current_pos < buf->buf_end) { + *buf->buf_current_pos++ = octet; + } + else + { + FatalError("ParsePattern() dummy " + "buffer overflow, make a smaller " + "pattern please! (Max size = 2048)\n"); + }; +} + + +static unsigned long ByteBufferSize(const ByteBuffer *buf) +{ + return (unsigned long)(buf->buf_current_pos - buf->buf_start); +} + + +/**************************************************************************** * * Function: ParsePattern(char *) * @@ -852,16 +896,13 @@ static void ParsePattern(char *rule, OptTreeNode * otn, int type) {
unsigned char tmp_buf[2048];
/* got enough ptrs for you? */
char *start_ptr;
char *end_ptr;
char *idx;
- char *dummy_idx;
- char *dummy_end;
char hex_buf[3];
- u_int dummy_size = 0; - int size;
int hexmode = 0;
int hexsize = 0;
int pending = 0;
@@ -870,9 +911,6 @@
int exception_flag = 0;
PatternMatchData *ds_idx;
- /* clear out the temp buffer */
- bzero(tmp_buf, 2048); -
if(rule == NULL)
{
FatalError("%s(%d) => ParsePattern Got Null "
@@ -913,22 +951,9 @@
/* Move the null termination up a bit more */
*end_ptr = '\0';
- /* how big is it?? */
- size = end_ptr - start_ptr;
-
- /* uh, this shouldn't happen */
- if(size <= 0)
- {
- FatalError("%s(%d) => Bad pattern length!\n",
- file_name, file_line);
- }
/* set all the pointers to the appropriate places... */
idx = start_ptr;
- /* set the indexes into the temp buffer */
- dummy_idx = tmp_buf;
- dummy_end = (dummy_idx + size); -
/* why is this buffer so small? */
bzero(hex_buf, 3);
memset(hex_buf, '0', 2);
@@ -963,8 +988,7 @@
{
DEBUG_WRAP(DebugMessage(DEBUG_PARSER, "literal set, Clearing\n"););
literal = 0;
- tmp_buf[dummy_size] = start_ptr[cnt];
- dummy_size++;
+ ds_idx->pattern_size = ByteBufferSize(&byte_buf); + ds_idx->search = uniSearch; + + if((ds_idx->pattern_buf = (char *) calloc(ds_idx->pattern_size+1, + sizeof(char))) == NULL)
{
FatalError("ParsePattern() pattern_buf malloc failed!\n");
}
- memcpy(ds_idx->pattern_buf, tmp_buf, dummy_size);
-
- ds_idx->pattern_size = dummy_size; - ds_idx->search = uniSearch; + memcpy(ds_idx->pattern_buf, tmp_buf, ds_idx->pattern_size);
make_precomp(ds_idx);
ds_idx->exception_flag = exception_flag;
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf Snort-devel mailing list Snort-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/snort-devel Received on Fri Sep 26 19:51:36 2003 This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 14:08:09 EDT |
||||||||||
|
|||||||||||