1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Trap large memory allocation requests.

This commit is contained in:
Alasdair Kergon 2004-11-24 21:34:56 +00:00
parent 2e6051674b
commit c3a4c63c15
4 changed files with 26 additions and 15 deletions

View File

@ -1,5 +1,6 @@
Version 2.00.27 - 24th November 2004
====================================
Trap large memory allocation requests.
Fix to partition table detection code.
Improve filter debug mesgs.

View File

@ -76,6 +76,7 @@ SOURCES =\
misc/crc.c \
misc/lvm-file.c \
misc/lvm-string.c \
mm/dbg_malloc.c \
mm/memlock.c \
mm/pool.c \
regex/matcher.c \
@ -121,10 +122,6 @@ ifeq ("@MIRRORS@", "internal")
SOURCES += mirror/mirrored.c
endif
ifeq ("@DEBUG@", "yes")
SOURCES += mm/dbg_malloc.c
endif
ifeq ("@DEVMAPPER@", "yes")
SOURCES +=\
activate/dev_manager.c \

View File

@ -19,6 +19,8 @@
#include <stdarg.h>
#ifdef DEBUG_MEM
struct memblock {
struct memblock *prev, *next; /* All allocated blocks are linked */
size_t length; /* Size of the requested block */
@ -47,7 +49,7 @@ void *malloc_aux(size_t s, const char *file, int line)
if (s > 50000000) {
log_error("Huge memory allocation (size %" PRIuPTR
") rejected - bug?", s);
") rejected - metadata corruption?", s);
return 0;
}
@ -166,7 +168,6 @@ void *realloc_aux(void *p, unsigned int s, const char *file, int line)
return r;
}
#ifdef DEBUG_MEM
int dump_memory(void)
{
unsigned long tot = 0;
@ -213,10 +214,18 @@ void bounds_check(void)
mb = mb->next;
}
}
#endif
/*
* Local variables:
* c-file-style: "linux"
* End:
*/
#else
void *malloc_aux(size_t s, const char *file, int line)
{
if (s > 50000000) {
log_error("Huge memory allocation (size %" PRIuPTR
") rejected - metadata corruption?", s);
return 0;
}
return malloc(s);
}
#endif

View File

@ -20,22 +20,26 @@
#include <stdlib.h>
#include <string.h>
#ifdef DEBUG_MEM
void *malloc_aux(size_t s, const char *file, int line);
# define dbg_malloc(s) malloc_aux((s), __FILE__, __LINE__)
#ifdef DEBUG_MEM
void free_aux(void *p);
void *realloc_aux(void *p, unsigned int s, const char *file, int line);
int dump_memory(void);
void bounds_check(void);
# define dbg_malloc(s) malloc_aux((s), __FILE__, __LINE__)
# define dbg_free(p) free_aux(p)
# define dbg_realloc(p, s) realloc_aux(p, s, __FILE__, __LINE__)
#else
# define dbg_malloc(s) malloc(s)
# define dbg_free(p) free(p)
# define dbg_realloc(p, s) realloc(p, s)
# define dump_memory()
# define bounds_check()
#endif
static inline char *dbg_strdup(const char *str)