~ubuntu-branches/ubuntu/lucid/bogofilter/lucid-security

« back to all changes in this revision

Viewing changes to src/token.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2009-05-06 05:41:52 UTC
  • mfrom: (1.1.11 upstream) (2.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090506054152-tgameecssbuv4np6
Tags: 1.2.0-2ubuntu1
* Merge from debian unstable, remaining changes: LP: #372497
  - don't build qdbm.
  - Don't build tokyocabinet support as it's in universe.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: token.c 6617 2007-01-12 00:20:16Z relson $ */
 
1
/* $Id: token.c 6788 2009-02-11 23:36:35Z relson $ */
2
2
 
3
3
/*****************************************************************************
4
4
 
95
95
 
96
96
    for (i = 0; i < multi_token_count; i += 1) {
97
97
        words->leng = 0;
98
 
        words->text = text;
 
98
        words->u.text = text;
99
99
        w_token_array[i] = words;
100
100
        words += 1;
101
101
        text += max_token_len+1+D;
106
106
{
107
107
    free(p_multi_words);
108
108
    free(p_multi_text );
 
109
    free(p_multi_buff );
109
110
    free(w_token_array);
110
111
}
111
112
 
112
113
static void token_set( word_t *token, byte *text, uint leng )
113
114
{
114
115
    token->leng = leng;
115
 
    memcpy(token->text, text, leng);            /* include nul terminator */
116
 
    token->text[leng] = '\0';                   /* ensure nul termination */
 
116
    memcpy(token->u.text, text, leng);          /* include nul terminator */
 
117
    token->u.text[leng] = '\0';                 /* ensure nul termination */
117
118
}
118
119
 
119
120
static inline void token_copy( word_t *dst, word_t *src )
120
121
{
121
 
    token_set(dst, src->text, src->leng);
 
122
    token_set(dst, src->u.text, src->leng);
122
123
}
123
124
 
124
125
static void build_prefixed_token( word_t *prefix, word_t *token,
130
131
        len = temp_size - prefix->leng - 1;
131
132
 
132
133
    temp->leng = len;
133
 
    memmove(temp->text+prefix->leng, token->text, len-prefix->leng);
134
 
    memcpy(temp->text, prefix->text, prefix->leng);
135
 
    Z(temp->text[temp->leng]);
 
134
    memmove(temp->u.text+prefix->leng, token->u.text, len-prefix->leng);
 
135
    memcpy(temp->u.text, prefix->u.text, prefix->leng);
 
136
    Z(temp->u.text[temp->leng]);
136
137
 
137
138
    token->leng = temp->leng;
138
 
    token->text = temp->text;
 
139
    token->u.text = temp->u.text;
139
140
}
140
141
 
141
142
#define WRAP(n) ((n) % multi_token_count)
186
187
    /* If saved IPADDR, truncate last octet */
187
188
    if ( block_on_subnets && save_class == IPADDR )
188
189
    {
189
 
        byte *t = xmemrchr(ipsave->text, '.', ipsave->leng);
 
190
        byte *t = xmemrchr(ipsave->u.text, '.', ipsave->leng);
190
191
        if (t == NULL)
191
192
            save_class = NONE;
192
193
        else
193
194
        {
194
 
            ipsave->leng = (uint) (t - ipsave->text);
195
 
            token_set( token, ipsave->text, ipsave->leng);
 
195
            ipsave->leng = (uint) (t - ipsave->u.text);
 
196
            token_set( token, ipsave->u.text, ipsave->leng);
196
197
            cls = save_class;
197
198
            done = true;
198
199
        }
205
206
        cls = (*lexer->yylex)();
206
207
 
207
208
        token->leng = (uint)   *lexer->yyleng;
208
 
        token->text = (byte *) *lexer->yytext;
209
 
        Z(token->text[token->leng]);    /* for easier debugging - removable */
 
209
        token->u.text = (byte *) *lexer->yytext;
 
210
        Z(token->u.text[token->leng]);  /* for easier debugging - removable */
210
211
 
211
212
        leng = token->leng;
212
 
        text = token->text;
 
213
        text = token->u.text;
213
214
 
214
215
        if (DEBUG_TEXT(2)) {
215
216
            word_puts(token, 0, dbgout);
261
262
                    *ot = *in;
262
263
                token->leng = leng = (uint) (ot - st);
263
264
            }
264
 
            Z(token->text[token->leng]);        /* for easier debugging - removable */
 
265
            Z(token->u.text[token->leng]);      /* for easier debugging - removable */
265
266
        }
266
267
        break;
267
268
 
283
284
        case TOKEN:     /* ignore anything when not reading text MIME types */
284
285
            if (leng < min_token_len)
285
286
                continue;
 
287
 
 
288
        /*@fallthrough@*/
 
289
 
286
290
        case MONEY:     /* 2 character money is OK */
287
291
            if (leng > max_token_len)
288
292
                continue;
289
293
 
290
 
            token->text = text;
 
294
            token->u.text = text;
291
295
            token->leng = leng;
292
296
 
293
297
            if (token_prefix == NULL) {
327
331
        case QUEUE_ID:
328
332
            /* special token;  saved for formatted output, but not returned to bogofilter */
329
333
            /** \bug: the parser MUST be aligned with lexer_v3.l! */
330
 
            if (*queue_id->text == '\0' &&
 
334
            if (*queue_id->u.text == '\0' &&
331
335
                leng < max_token_len )
332
336
            {
333
337
                while (isspace(text[0])) {
350
354
                    leng -= 1;
351
355
                }
352
356
                leng = min(queue_id->leng, leng);
353
 
                memcpy( queue_id->text, text, leng );
354
 
                Z(queue_id->text[leng]);
 
357
                memcpy( queue_id->u.text, text, leng );
 
358
                Z(queue_id->u.text[leng]);
355
359
            }
356
360
            continue;
357
361
 
365
369
            /* if top level, no address, not localhost, .... */
366
370
            if (token_prefix == w_recv &&
367
371
                msg_state->parent == NULL && 
368
 
                *msg_addr->text == '\0' &&
 
372
                *msg_addr->u.text == '\0' &&
369
373
                strcmp((char *)text, "127.0.0.1") != 0)
370
374
            {
371
375
                /* Not guaranteed to be the originating address of the message. */
372
 
                memcpy( msg_addr->text, yylval.text, min(msg_addr->leng, yylval.leng)+D );
373
 
                Z(msg_addr->text[yylval.leng]);
 
376
                memcpy( msg_addr->u.text, yylval.u.text, min(msg_addr->leng, yylval.leng)+D );
 
377
                Z(msg_addr->u.text[yylval.leng]);
374
378
            }
375
379
        }
376
380
 
398
402
                            q1 & 0xff, q2 & 0xff, q3 & 0xff, q4 & 0xff);
399
403
                leng = strlen((const char *)text);
400
404
 
401
 
                token->text = text;
 
405
                token->u.text = text;
402
406
                token->leng = leng;
403
407
 
404
408
                token_copy( ipsave, token );
408
412
                return (cls);
409
413
            }
410
414
 
411
 
            token->text = text;
 
415
            token->u.text = text;
412
416
            token->leng = leng;
413
417
 
414
418
            break;
448
452
   if (!msg_count_file) {
449
453
        /* Remove trailing blanks */
450
454
        /* From "From ", for example */
451
 
        while (token->leng > 1 && token->text[token->leng-1] == ' ') {
 
455
        while (token->leng > 1 && token->u.text[token->leng-1] == ' ') {
452
456
            token->leng -= 1;
453
 
            token->text[token->leng] = (byte) '\0';
 
457
            token->u.text[token->leng] = (byte) '\0';
454
458
        }
455
459
 
456
460
        /* Remove trailing colon */
457
 
        if (token->leng > 1 && token->text[token->leng-1] == ':') {
 
461
        if (token->leng > 1 && token->u.text[token->leng-1] == ':') {
458
462
            token->leng -= 1;
459
 
            token->text[token->leng] = (byte) '\0';
 
463
            token->u.text[token->leng] = (byte) '\0';
460
464
        }
461
465
 
462
466
        if (replace_nonascii_characters) {
463
467
            /* replace nonascii characters by '?'s */
464
 
            for (cp = token->text; cp < token->text+token->leng; cp += 1)
 
468
            for (cp = token->u.text; cp < token->u.text+token->leng; cp += 1)
465
469
                *cp = casefold_table[*cp];
466
470
        }
467
471
    }
476
480
    word_t *w = w_token_array[WRAP(tok_count)];
477
481
 
478
482
    w->leng = token->leng;
479
 
    memcpy(w->text, token->text, w->leng);
480
 
    Z(w->text[w->leng]);        /* for easier debugging - removable */
 
483
    memcpy(w->u.text, token->u.text, w->leng);
 
484
    Z(w->u.text[w->leng]);      /* for easier debugging - removable */
481
485
 
482
486
    if (DEBUG_MULTI(1))
483
487
        fprintf(stderr, "%s:%d  %2s  %2d %2d %p %s\n", __FILE__, __LINE__,
484
 
                "", tok_count, w->leng, w->text, w->text);
 
488
                "", tok_count, w->leng, w->u.text, w->u.text);
485
489
 
486
490
    tok_count += 1;
487
491
    init_token = 1;
500
504
    leng = init_token;
501
505
    for ( tok = init_token; tok >= 0; tok -= 1 ) {
502
506
        uint idx = tok_count - 1 - tok;
503
 
        leng += strlen((char *) w_token_array[WRAP(idx)]->text);
 
507
        leng += strlen((char *) w_token_array[WRAP(idx)]->u.text);
504
508
    }
505
509
 
506
510
    if (leng > max_multi_token_len)
507
511
        leng = max_multi_token_len;
508
512
 
509
513
    token->leng = leng;
510
 
    token->text = dest = p_multi_buff;
 
514
    token->u.text = dest = p_multi_buff;
511
515
 
512
516
    for ( tok = init_token; tok >= 0; tok -= 1 ) {
513
517
        uint  idx = tok_count - 1 - tok;
514
518
        uint  len = w_token_array[WRAP(idx)]->leng;
515
 
        byte *str = w_token_array[WRAP(idx)]->text;
 
519
        byte *str = w_token_array[WRAP(idx)]->u.text;
516
520
 
517
521
        if (DEBUG_MULTI(1))
518
522
            fprintf(stderr, "%s:%d  %2d  %2d %2d %p %s\n", __FILE__, __LINE__,
529
533
        sep = "*";
530
534
    }
531
535
 
532
 
    Z(token->text[token->leng]);        /* for easier debugging - removable */
 
536
    Z(token->u.text[token->leng]);      /* for easier debugging - removable */
533
537
    init_token += 1;                    /* progress to next multi-token */
534
538
 
535
539
    return;
564
568
 
565
569
        yylval_text = (byte *) malloc( yylval_text_size+D );
566
570
        yylval.leng   = 0;
567
 
        yylval.text   = yylval_text;
 
571
        yylval.u.text   = yylval_text;
568
572
 
569
573
        /* First IP Address in Received: statement */
570
574
        msg_addr = word_new( NULL, max_token_len );
694
698
{
695
699
    if (msg_addr != NULL)
696
700
    {
697
 
        *msg_addr->text = '\0';
698
 
        *msg_id->text   = '\0';
699
 
        *queue_id->text = '\0';
 
701
        *msg_addr->u.text = '\0';
 
702
        *msg_id->u.text   = '\0';
 
703
        *queue_id->u.text = '\0';
700
704
    }
701
705
}