summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorAlexey Kopytov <Alexey.Kopytov@Sun.com>2010-05-21 15:23:48 +0400
committerAlexey Kopytov <Alexey.Kopytov@Sun.com>2010-05-21 15:23:48 +0400
commitc2ebb0ac882feadedd0bbca71277fd2de66aa957 (patch)
tree393cb5d35a1dc953f8e9fee7b6c06737b675ba9c /mysys
parent36be33b0ad829732b76d87f6d618546014fd96de (diff)
downloadmariadb-git-c2ebb0ac882feadedd0bbca71277fd2de66aa957.tar.gz
Bug #42064: low memory crash when importing hex strings, in
Item_hex_string::Item_hex_string The status of memory allocation in the Lex_input_stream (called from the Parser_state constructor) was not checked which led to a parser crash in case of the out-of-memory error. The solution is to introduce new init() member function in Parser_state and Lex_input_stream so that status of memory allocation can be returned to the caller. mysql-test/r/error_simulation.result: Added a test case for bug #42064. mysql-test/t/error_simulation.test: Added a test case for bug #42064. mysys/my_alloc.c: Added error injection code for the regression test. mysys/my_malloc.c: Added error injection code for the regression test. mysys/safemalloc.c: Added error injection code for the regression test. sql/event_data_objects.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/mysqld.cc: Added error injection code for the regression test. sql/sp.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/sql_lex.cc: Moved memory allocation from constructor to the separate init() member function. Added error injection code for the regression test. sql/sql_lex.h: Moved memory allocation from constructor to the separate init() member function. sql/sql_parse.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/sql_partition.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/sql_prepare.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/sql_trigger.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures. sql/sql_view.cc: Use the new init() member function of Parser_state and check its return value to handle memory allocation failures.. sql/thr_malloc.cc: Added error injection code for the regression test.
Diffstat (limited to 'mysys')
-rw-r--r--mysys/my_alloc.c16
-rw-r--r--mysys/my_malloc.c12
-rw-r--r--mysys/safemalloc.c7
3 files changed, 34 insertions, 1 deletions
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
index 2607ea57d08..dd27dcda41e 100644
--- a/mysys/my_alloc.c
+++ b/mysys/my_alloc.c
@@ -154,6 +154,14 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
DBUG_ASSERT(alloc_root_inited(mem_root));
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ {
+ if (mem_root->error_handler)
+ (*mem_root->error_handler)();
+ DBUG_SET("-d,simulate_out_of_memory");
+ DBUG_RETURN((void*) 0); /* purecov: inspected */
+ });
+
length+=ALIGN_SIZE(sizeof(USED_MEM));
if (!(next = (USED_MEM*) my_malloc(length,MYF(MY_WME))))
{
@@ -176,6 +184,14 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
DBUG_PRINT("enter",("root: 0x%lx", (long) mem_root));
DBUG_ASSERT(alloc_root_inited(mem_root));
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ {
+ /* Avoid reusing an already allocated block */
+ if (mem_root->error_handler)
+ (*mem_root->error_handler)();
+ DBUG_SET("-d,simulate_out_of_memory");
+ DBUG_RETURN((void*) 0); /* purecov: inspected */
+ });
length= ALIGN_SIZE(length);
if ((*(prev= &mem_root->free)) != NULL)
{
diff --git a/mysys/my_malloc.c b/mysys/my_malloc.c
index 12793ad451b..13d2375eb99 100644
--- a/mysys/my_malloc.c
+++ b/mysys/my_malloc.c
@@ -31,13 +31,23 @@ void *my_malloc(size_t size, myf my_flags)
if (!size)
size=1; /* Safety */
- if ((point = (char*)malloc(size)) == NULL)
+
+ point= (char *) malloc(size);
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ {
+ free(point);
+ point= NULL;
+ });
+
+ if (point == NULL)
{
my_errno=errno;
if (my_flags & MY_FAE)
error_handler_hook=fatal_error_handler_hook;
if (my_flags & (MY_FAE+MY_WME))
my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG+ME_NOREFRESH),size);
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ DBUG_SET("-d,simulate_out_of_memory"););
if (my_flags & MY_FAE)
exit(1);
}
diff --git a/mysys/safemalloc.c b/mysys/safemalloc.c
index c484f1d4c54..938ecd9dde8 100644
--- a/mysys/safemalloc.c
+++ b/mysys/safemalloc.c
@@ -139,6 +139,11 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags)
size + /* size requested */
4 + /* overrun mark */
sf_malloc_endhunc);
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ {
+ free(irem);
+ irem= NULL;
+ });
}
/* Check if there isn't anymore memory avaiable */
if (!irem)
@@ -159,6 +164,8 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags)
}
DBUG_PRINT("error",("Out of memory, in use: %ld at line %d, '%s'",
sf_malloc_max_memory,lineno, filename));
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ DBUG_SET("-d,simulate_out_of_memory"););
if (MyFlags & MY_FAE)
exit(1);
DBUG_RETURN ((void*) 0);