5ca7fd18 |
/* |
a7e14794 |
* Copyright (C) 2015, 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved. |
5ca7fd18 |
* Copyright (C) 2007 Sourcefire, Inc.
*
* The unRAR sources may be used in any software to handle RAR
* archives without limitations free of charge, but cannot be used
* to re-create the RAR compression algorithm, which is proprietary.
* Distribution of modified unRAR sources in separate form or as a
* part of other software is permitted, provided that it is clearly
* stated in the documentation and source comments that the code may
* not be used to develop a RAR (WinRAR) compatible archiver.
*/
#include <stdio.h>
#include <stdlib.h>
#include "libclamunrar/unrarhlp.h"
|
a5b7bfab |
#ifdef RAR_HIGH_DEBUG
#define rar_dbgmsg printf
#else |
a7e14794 |
static void rar_dbgmsg(const char* fmt,...){(void)fmt;} |
a5b7bfab |
#endif
|
5ca7fd18 |
#define RAR_MAX_ALLOCATION 184549376
void *rar_malloc(size_t size)
{
void *alloc;
if(!size || size > RAR_MAX_ALLOCATION) { |
a5b7bfab |
rar_dbgmsg("UNRAR: rar_malloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", size); |
5ca7fd18 |
return NULL;
}
alloc = malloc(size);
if(!alloc) { |
059ca614 |
fprintf(stderr, "UNRAR: rar_malloc(): Can't allocate memory (%llu bytes).\n", (long long unsigned)size); |
5ca7fd18 |
return NULL;
} else return alloc;
}
void *rar_realloc2(void *ptr, size_t size)
{
void *alloc;
if(!size || size > RAR_MAX_ALLOCATION) { |
a5b7bfab |
rar_dbgmsg("UNRAR: rar_realloc2(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", size); |
5ca7fd18 |
return NULL;
}
alloc = realloc(ptr, size);
if(!alloc) { |
059ca614 |
fprintf(stderr, "UNRAR: rar_realloc2(): Can't allocate memory (%llu bytes).\n", (long long unsigned)size); |
5ca7fd18 |
if(ptr)
free(ptr);
return NULL;
} else return alloc;
} |