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

« back to all changes in this revision

Viewing changes to src/lexer.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: lexer.c 6719 2008-04-26 12:51:17Z relson $ */
 
1
/* $Id: lexer.c 6766 2009-01-12 04:27:36Z relson $ */
2
2
 
3
3
/**
4
4
 * \file lexer.c
75
75
            yylineno-1, msg_header ? 'h' : 'b', yy_get_state(),
76
76
            (long)(buff->t.leng - buff->read));
77
77
    buff_puts(buff, 0, dbgout);
78
 
    if (buff->t.leng > 0 && buff->t.text[buff->t.leng-1] != '\n')
 
78
    if (buff->t.leng > 0 && buff->t.u.text[buff->t.leng-1] != '\n')
79
79
        fputc('\n', dbgout);
80
80
}
81
81
 
105
105
static int yy_get_new_line(buff_t *buff)
106
106
{
107
107
    int count = (*reader_getline)(buff);
108
 
    const byte *buf = buff->t.text;
 
108
    const byte *buf = buff->t.u.text;
109
109
 
110
110
    static size_t hdrlen = 0;
111
111
    if (hdrlen==0)
142
142
           && count != EOF
143
143
/* don't skip if inside message/rfc822 */
144
144
           && msg_state->parent == NULL
145
 
           && memcmp(buff->t.text,spam_header_name,hdrlen) == 0) {
 
145
           && memcmp(buff->t.u.text,spam_header_name,hdrlen) == 0) {
146
146
        count = skip_folded_line(buff);
147
147
    }
148
148
 
171
171
         * sufficiently small that the UTF-8 text can fit in the output
172
172
         * buffer */
173
173
        if (tempbuff->size < buff->size / 6) {
174
 
            xfree(tempbuff->t.text);
 
174
            xfree(tempbuff->t.u.text);
175
175
            tempbuff->size = buff->size / 6;
176
 
            tempbuff->t.text = (byte *) xmalloc(tempbuff->size+D);
 
176
            tempbuff->t.u.text = (byte *) xmalloc(tempbuff->size+D);
177
177
        }
178
178
 
179
179
        tempbuff->t.leng = tempbuff->read = 0;
198
198
     * than one of these. */
199
199
 
200
200
    if (passthrough && passmode == PASS_MEM && count > 0)
201
 
        textblock_add(linebuff->t.text+linebuff->read, (size_t) count);
 
201
        textblock_add(linebuff->t.u.text+linebuff->read, (size_t) count);
202
202
 
203
203
    if ( !msg_header && 
204
204
         !msg_state->mime_dont_decode &&
208
208
        uint decoded_count;
209
209
 
210
210
        temp.leng = (uint) count;
211
 
        temp.text = linebuff->t.text+linebuff->read;
 
211
        temp.u.text = linebuff->t.u.text+linebuff->read;
212
212
 
213
213
        decoded_count = mime_decode(&temp);
214
214
        /*change buffer size only if the decoding worked */
243
243
 
244
244
    /* CRLF -> NL */
245
245
    if (count >= 2) {
246
 
        byte *buf = buff->t.text;
 
246
        byte *buf = buff->t.u.text;
247
247
        if (memcmp(buf + count - 2, CRLF, 2) == 0) {
248
248
            count --;
249
249
            *(buf + count - 1) = (byte) '\n';
251
251
    }
252
252
 
253
253
    if (buff->t.leng < buff->size)     /* for easier debugging - removable */
254
 
        Z(buff->t.text[buff->t.leng]);  /* for easier debugging - removable */
 
254
        Z(buff->t.u.text[buff->t.leng]);  /* for easier debugging - removable */
255
255
 
256
256
    return count;
257
257
}
265
265
        yylineno += 1;
266
266
        /* only check for LWSP-char (RFC-822) aka. WSP (RFC-2822),
267
267
         * these only include SP and HTAB */
268
 
        if (buff->t.text[0] != ' ' &&
269
 
            buff->t.text[0] != '\t')
 
268
        if (buff->t.u.text[0] != ' ' &&
 
269
            buff->t.u.text[0] != '\t')
270
270
            return count;
271
271
        /* Check for empty line which terminates message header */
272
 
        if (is_eol((char *)buff->t.text, count))
 
272
        if (is_eol((char *)buff->t.u.text, count))
273
273
            return count;
274
274
    }
275
275
}
334
334
            break;
335
335
 
336
336
        if (count >= MAX_TOKEN_LEN * 2 && 
337
 
            long_token(buff.t.text, (uint) count)) {
 
337
            long_token(buff.t.u.text, (uint) count)) {
338
338
            uint start = buff.t.leng - count;
339
339
            uint length = count - max_token_len;
340
340
            buff_shift(&buff, start, length);
391
391
word_t *text_decode(word_t *w)
392
392
{
393
393
    word_t *r = w;
394
 
    byte *const beg = w->text;          /* base pointer, fixed */
 
394
    byte *const beg = w->u.text;                /* base pointer, fixed */
395
395
    byte *const fin = beg + w->leng;    /* end+1 position */
396
396
 
397
 
    byte *txt = (byte *) memstr(w->text, w->leng, "=?");        /* input position */
 
397
    byte *txt = (byte *) memstr(w->u.text, w->leng, "=?");      /* input position */
398
398
    uint size = (uint) (txt - beg);                             /* output offset */
399
399
 
400
400
#ifndef DISABLE_UNICODE
414
414
        buf->t.leng = 0;
415
415
        if (buf->size < max) {
416
416
            buf->size = max;
417
 
            buf->t.text = (byte *) xrealloc(buf->t.text, buf->size+D);
 
417
            buf->t.u.text = (byte *) xrealloc(buf->t.u.text, buf->size+D);
418
418
        }
419
419
 
420
420
        buf->t.leng = size;
421
 
        memcpy(buf->t.text, beg, size );
422
 
        Z(buf->t.text[buf->t.leng]);            /* for easier debugging - removable */
 
421
        memcpy(buf->t.u.text, beg, size );
 
422
        Z(buf->t.u.text[buf->t.leng]);          /* for easier debugging - removable */
423
423
    }
424
424
#endif
425
425
 
446
446
        end = (byte *) memstr((char *)tmp, fin-tmp, "?=");      /* last byte of encoded word  */
447
447
        len = end - tmp;
448
448
 
449
 
        w->text = tmp;                          /* Start of encoded word */
 
449
        w->u.text = tmp;                                /* Start of encoded word */
450
450
        w->leng = len;                          /* Length of encoded word */
451
 
        Z(w->text[w->leng]);                    /* for easier debugging - removable */
 
451
        Z(w->u.text[w->leng]);                  /* for easier debugging - removable */
452
452
 
453
453
        if (DEBUG_LEXER(2)) {
454
454
            fputs("**2**  ", dbgout);
469
469
 
470
470
        /* move decoded word to where the encoded used to be */
471
471
        if (encoding == E_RAW) {
472
 
            memmove(beg+size, w->text, len);
 
472
            memmove(beg+size, w->u.text, len);
473
473
            size += len;                        /* bump output pointer */
474
474
            Z(beg[size]);                       /* for easier debugging - removable */
475
475
 
485
485
            /* convert 'word_t *w' to 'buff_t src' because
486
486
            ** iconvert_cd() needs buff_t pointers
487
487
            */
488
 
            src.t.text = w->text;
 
488
            src.t.u.text = w->u.text;
489
489
            src.t.leng = len;
490
490
            src.read   = 0;
491
491
            src.size   = len;
534
534
                    beg[size++] = *txt++;
535
535
#ifndef DISABLE_UNICODE
536
536
                if (encoding == E_UNICODE)
537
 
                    buf->t.text[buf->t.leng++] = *txt++;
 
537
                    buf->t.u.text[buf->t.leng++] = *txt++;
538
538
#endif
539
539
            }
540
540
    }
541
541
 
542
542
    if (encoding == E_RAW) {
543
 
        r->text = beg;
 
543
        r->u.text = beg;
544
544
        r->leng = size;
545
545
    }
546
546