~ubuntu-branches/ubuntu/feisty/clamav/feisty-updates

« back to all changes in this revision

Viewing changes to libclamav/rtf.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-04-29 14:10:40 UTC
  • mfrom: (0.11.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080429141040-hczapuc6b7ja904q
Tags: 0.92.1~dfsg2-1.1~feisty1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  Copyright (C) 2006 T�r�k Edwin <edwin@clamav.net>
3
3
 *
4
4
 *  This program is free software; you can redistribute it and/or modify
5
 
 *  it under the terms of the GNU General Public License as published by
6
 
 *  the Free Software Foundation; either version 2 of the License, or
7
 
 *  (at your option) any later version.
 
5
 *  it under the terms of the GNU General Public License version 2 as 
 
6
 *  published by the Free Software Foundation.
8
7
 *
9
8
 *  This program is distributed in the hope that it will be useful,
10
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
125
124
       0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
126
125
};
127
126
 
128
 
extern int short cli_leavetemps_flag;
129
 
 
130
127
static void init_rtf_state(struct rtf_state* state)
131
128
{
132
129
        *state = base_state;
161
158
        if(stack->stack_cnt >= stack->stack_size) {
162
159
                /* grow stack */
163
160
                stack->stack_size += 128;
164
 
                stack->states = cli_realloc(stack->states, stack->stack_size*sizeof(*stack->states));
 
161
                stack->states = cli_realloc2(stack->states, stack->stack_size*sizeof(*stack->states));
165
162
                if(!stack->states)
166
163
                        return CL_EMEM;
167
164
        }
268
265
        const unsigned char* out_data;
269
266
        size_t out_cnt = 0;
270
267
        size_t i;
 
268
        int ret;
271
269
 
272
270
        if(!data || !len)
273
271
                return 0;
306
304
                                                 cli_dbgmsg("RTF: waiting for magic\n");
307
305
                                                 for(i=0; i<out_cnt && data->bread < rtf_data_magic_len; i++, data->bread++)
308
306
                                                         if(rtf_data_magic[data->bread] != out_data[i]) {
309
 
                                                                 cli_dbgmsg("Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu\n",rtf_data_magic[i],out_data[i],data->bread);
 
307
                                                                cli_dbgmsg("Warning: rtf objdata magic number not matched, expected:%d, got: %d, at pos:%lu\n",rtf_data_magic[i],out_data[i], (unsigned long int) data->bread);
310
308
                                                         }
311
309
                                                 out_cnt  -= i;
312
310
                                                 if(data->bread == rtf_data_magic_len) {
326
324
                                                            out_data += i;
327
325
                                                            data->bread=0;
328
326
                                                            if(data->desc_len > 64) {
329
 
                                                                    cli_dbgmsg("Description length too big (%lu), showing only 64 bytes of it\n",data->desc_len);
 
327
                                                            cli_dbgmsg("Description length too big (%lu), showing only 64 bytes of it\n", (unsigned long int) data->desc_len);
330
328
                                                                    data->desc_name = cli_malloc(65);
331
329
                                                            }
332
330
                                                            else
335
333
                                                                    return CL_EMEM;
336
334
                                                            }
337
335
                                                            data->internal_state = WAIT_DESC;
338
 
                                                            cli_dbgmsg("RTF: description length:%lu\n",data->desc_len);
 
336
                                                            cli_dbgmsg("RTF: description length:%lu\n", (unsigned long int) data->desc_len);
339
337
                                                    }
340
338
                                                    break;
341
339
                                            }
394
392
                                                    if(data->bread == 4) {
395
393
                                                            out_data += i;
396
394
                                                            data->bread=0;
397
 
                                                            cli_dbgmsg("Dumping rtf embedded object of size:%ld\n",data->desc_len);
398
 
                                                            data->name = cli_gentempdesc(data->tmpdir, &data->fd);
399
 
                                                            if(!data->name || data->fd < 0)
400
 
                                                                    return CL_ETMPFILE;
 
395
                                                            cli_dbgmsg("Dumping rtf embedded object of size:%lu\n", (unsigned long int) data->desc_len);
 
396
                                                            if((ret = cli_gentempfd(data->tmpdir, &data->name, &data->fd)))
 
397
                                                                    return ret;
401
398
                                                            data->internal_state = DUMP_DATA;
402
399
                                                            cli_dbgmsg("RTF: next state: DUMP_DATA\n");
403
400
                                                    }
607
604
                                                                                         return ret;
608
605
                                                                                }
609
606
                                                                        if(( ret = state.cb_process(&state, ptr, use) )) {
610
 
                                                                                state.cb_end(&state,ctx);
 
607
                                                                                if(state.cb_end) {
 
608
                                                                                        state.cb_end(&state,ctx);
 
609
                                                                                }
611
610
                                                                                SCAN_CLEANUP;
612
611
                                                                                return ret;
613
612
                                                                        }
678
677
                                                if(action != -1) {
679
678
                                                        if(state.cb_data && state.cb_end) {/* premature end of previous block */
680
679
                                                                state.cb_end(&state,ctx);
 
680
                                                                state.cb_begin = NULL;
681
681
                                                                state.cb_end = NULL;
682
682
                                                                state.cb_data = NULL;
683
683
                                                        }