[cvs] bogofilter/src collect.c,1.44,1.45 token.c,1.102,1.103 word.c,1.19,1.20
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: David R. <re...@us...> - 2005-03-13 16:38:25
|
Update of /cvsroot/bogofilter/bogofilter/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13533 Modified Files: collect.c token.c word.c Log Message: Ensure nul termination for tokens. Index: token.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/token.c,v retrieving revision 1.102 retrieving revision 1.103 diff -u -d -r1.102 -r1.103 --- token.c 13 Mar 2005 15:10:24 -0000 1.102 +++ token.c 13 Mar 2005 16:38:13 -0000 1.103 @@ -72,8 +72,8 @@ static void token_set( word_t *token, byte *text, uint leng ) { token->leng = leng; - memcpy(token->text, text, leng + D); - Z(token->text[leng]); + memcpy(token->text, text, leng + 1); /* include nul terminator */ + token->text[leng] = '\0'; /* ensure nul termination */ } static inline void token_copy( word_t *dst, word_t *src ) @@ -84,15 +84,15 @@ static void build_prefixed_token( word_t *token, word_t *prefix, byte *text, uint32_t leng ) { if (token_prefix != NULL) { - token->leng = leng + prefix->leng; - memcpy(token->text, prefix->text, prefix->leng + D); - memcpy(token->text + prefix->leng, text, leng + D); - Z(token->text[token->leng]); + token->leng = leng +prefix->leng; + memcpy(token->text, prefix->text, prefix->leng); + memcpy(token->text +prefix->leng, text, leng + 1); /* include nul terminator */ + token->text[token->leng] = '\0'; /* ensure nul termination */ } else { token->leng = leng; - memcpy(token->text, text, leng + D); - Z(token->text[token->leng]); + memcpy(token->text, text, leng + 1); /* include nul terminator */ + token->text[token->leng] = '\0'; /* ensure nul termination */ } } @@ -125,12 +125,12 @@ leng = (uint) *lexer->yyleng; text = (byte *) *lexer->yytext; - + if (DEBUG_TEXT(2)) { word_puts(&yylval, 0, dbgout); fputc('\n', dbgout); } - + if (cls == NONE) /* End of message */ break; @@ -175,6 +175,7 @@ *ot = *in; leng = (uint) (ot - st); } + text[leng] = '\0'; /* ensure nul termination */ build_prefixed_token( &yylval, token_prefix, text, leng ); } break; @@ -219,14 +220,17 @@ /** \bug: the parser MUST be aligned with lexer_v3.l! */ if (leng < sizeof(msg_id_text)) { - size_t skip = 0; - while (!isspace(yylval.text[skip])) - skip += 1; - while (isspace(yylval.text[skip])) - skip += 1; - yylval.leng -= skip; - memmove(yylval.text, yylval.text+skip, yylval.leng); - Z(yylval.text[yylval.leng]); + while (!isspace(text[0])) { + text += 1; + leng -= 1; + } + while (isspace(text[0])) { + text += 1; + leng -= 1; + } + text[leng] = '\0'; /* ensure nul termination */ + + token_set( &yylval, text, leng); token_copy( &msg_id, &yylval ); } continue; @@ -237,14 +241,20 @@ if (queue_id.leng == 0 && leng < sizeof(msg_id_text) ) { - size_t skip = 0; - while (isspace(text[skip])) - skip += 1; - if (memcmp(text+skip, "id", 2) == 0) - skip += 2; - while (isspace(text[skip])) - skip += 1; - token_set( &yylval, text+skip, leng-skip); + while (isspace(text[0])) { + text += 1; + leng -= 1; + } + if (memcmp(text, "id", 2) == 0) { + text += 2; + leng -= 2; + } + while (isspace(text[0])) { + text += 1; + leng -= 1; + } + text[leng] = '\0'; /* ensure nul termination */ + token_set( &yylval, text, leng); token_copy( &queue_id, &yylval ); } continue; @@ -252,9 +262,9 @@ case MESSAGE_ADDR: { /* trim brackets */ - - leng -= 2; text += 1; + leng -= 2; + text[leng] = '\0'; /* ensure nul termination */ token_set( &yylval, text, leng); /* if top level, no address, not localhost, .... */ if (token_prefix == &w_recv && @@ -334,7 +344,7 @@ done = true; } - if (!msg_count_file) { + if (!msg_count_file) { /* Remove trailing blanks */ /* From "From ", for example */ while (yylval.leng > 1 && yylval.text[yylval.leng-1] == ' ') { Index: collect.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/collect.c,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- collect.c 13 Mar 2005 01:54:32 -0000 1.44 +++ collect.c 13 Mar 2005 16:38:13 -0000 1.45 @@ -58,8 +58,8 @@ char *end = strchr(beg, '"'); assert(end); token->leng = end - beg; - memmove(token->text, token->text + 1, token->leng + D); - Z(token->text[token->leng]); /* replace terminal quote by NUL */ + memmove(token->text, token->text + 1, token->leng + 1); + token->text[token->leng] = '\0'; /* ensure nul termination */ } wp = wordhash_insert(wh, token, sizeof(wordprop_t), &wordprop_init); Index: word.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/word.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- word.c 4 Jan 2005 16:01:44 -0000 1.19 +++ word.c 13 Mar 2005 16:38:13 -0000 1.20 @@ -17,12 +17,12 @@ { /* to lessen malloc/free calls, allocate struct and data in one block */ uint len = (leng || !text) ? leng : (uint) strlen((const char *) text); - word_t *self = xmalloc(sizeof(word_t)+len+D); + word_t *self = xmalloc(sizeof(word_t)+len+1); self->leng = len; self->text = (byte *)((char *)self+sizeof(word_t)); if (text) { memcpy(self->text, text, len); - Z(self->text[len]); /* for easier debugging - removable */ + self->text[len] = '\0'; /* ensure nul termination */ } return self; } @@ -34,12 +34,12 @@ word_t *word_dup(const word_t *word) { - word_t *self = xmalloc(sizeof(word_t)+word->leng+D); + word_t *self = xmalloc(sizeof(word_t)+word->leng+1); self->leng = word->leng; self->text = (byte *)((char *)self+sizeof(word_t)); if (word->text) { memcpy(self->text, word->text, self->leng); - Z(self->text[self->leng]); /* for easier debugging - removable */ + self->text[self->leng] = '\0'; /* ensure nul termination */ } return self; } |