~ubuntu-branches/ubuntu/hardy/file/hardy-proposed

« back to all changes in this revision

Viewing changes to src/funcs.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2007-06-01 20:29:00 UTC
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20070601202900-gzjrg1s331z9632p
Tags: upstream-4.21
ImportĀ upstreamĀ versionĀ 4.21

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 */
27
27
#include "file.h"
28
28
#include "magic.h"
29
 
#include <assert.h>
30
29
#include <stdarg.h>
31
30
#include <stdlib.h>
32
31
#include <string.h>
37
36
#if defined(HAVE_WCTYPE_H)
38
37
#include <wctype.h>
39
38
#endif
 
39
#if defined(HAVE_LIMITS_H)
 
40
#include <limits.h>
 
41
#endif
 
42
#ifndef SIZE_T_MAX
 
43
#ifdef __LP64__
 
44
#define SIZE_T_MAX (size_t)0xfffffffffffffffffU
 
45
#else
 
46
#define SIZE_T_MAX (size_t)0xffffffffU
 
47
#endif
 
48
#endif
40
49
 
41
50
#ifndef lint
42
 
FILE_RCSID("@(#)$File: funcs.c,v 1.28 2007/03/01 22:14:54 christos Exp $")
 
51
FILE_RCSID("@(#)$File: funcs.c,v 1.32 2007/05/24 17:22:27 christos Exp $")
43
52
#endif  /* lint */
44
53
 
45
54
#ifndef HAVE_VSNPRINTF
219
228
                return -1;
220
229
        }
221
230
        ms->o.ptr = ms->o.buf;
 
231
        ms->o.left = ms->o.size;
222
232
        ms->haderr = 0;
223
233
        ms->error = -1;
224
234
        return 0;
246
256
 
247
257
        len = ms->o.size - ms->o.left;
248
258
        /* * 4 is for octal representation, + 1 is for NUL */
 
259
        if (len > (SIZE_T_MAX - 1) / 4) {
 
260
                file_oomem(ms, len);
 
261
                return NULL;
 
262
        }
249
263
        psize = len * 4 + 1;
250
 
        assert(psize > len);
251
264
        if (ms->o.psize < psize) {
252
265
                if ((pbuf = realloc(ms->o.pbuf, psize)) == NULL) {
253
266
                        file_oomem(ms, psize);
307
320
        return ms->o.pbuf;
308
321
}
309
322
 
 
323
protected int
 
324
file_check_mem(struct magic_set *ms, unsigned int level)
 
325
{
 
326
        size_t len;
 
327
 
 
328
        if (level >= ms->c.len) {
 
329
                len = (ms->c.len += 20) * sizeof(*ms->c.li);
 
330
                ms->c.li = (ms->c.li == NULL) ? malloc(len) :
 
331
                    realloc(ms->c.li, len);
 
332
                if (ms->c.li == NULL) {
 
333
                        file_oomem(ms, len);
 
334
                        return -1;
 
335
                }
 
336
        }
 
337
        ms->c.li[level].got_match = 0;
 
338
#ifdef ENABLE_CONDITIONALS
 
339
        ms->c.li[level].last_match = 0;
 
340
        ms->c.li[level].last_cond = COND_NONE;
 
341
#endif /* ENABLE_CONDITIONALS */
 
342
        return 0;
 
343
}
310
344
/*
311
345
 * Yes these wrappers suffer from buffer overflows, but if your OS does not
312
346
 * have the real functions, maybe you should consider replacing your OS?