about summary refs log tree commit diff stats
path: root/miasm2/jitter/vm_mngr.c
diff options
context:
space:
mode:
authorserpilliere <serpilliere@users.noreply.github.com>2017-07-24 11:18:16 +0200
committerGitHub <noreply@github.com>2017-07-24 11:18:16 +0200
commit051c1d2d7f1c58effd716e35f7b6897dcbe45488 (patch)
tree9eac332a43c4804c3ebecbe088a7789c548445b4 /miasm2/jitter/vm_mngr.c
parentc131b203e3389a652ea14231a4528b6cddb07067 (diff)
parent342a7fc31f2349e6c100cea610bceedbf965ad07 (diff)
downloadmiasm-051c1d2d7f1c58effd716e35f7b6897dcbe45488.tar.gz
miasm-051c1d2d7f1c58effd716e35f7b6897dcbe45488.zip
Merge pull request #582 from WilliamBruneau/realloc_check_return
Add null pointer check after realloc
Diffstat (limited to 'miasm2/jitter/vm_mngr.c')
-rw-r--r--miasm2/jitter/vm_mngr.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/miasm2/jitter/vm_mngr.c b/miasm2/jitter/vm_mngr.c
index 1114185b..0df1abaf 100644
--- a/miasm2/jitter/vm_mngr.c
+++ b/miasm2/jitter/vm_mngr.c
@@ -103,6 +103,10 @@ void memory_access_list_add(struct memory_access_list * access, uint64_t start,
 		else
 			access->allocated *= 2;
 		access->array = realloc(access->array, access->allocated * sizeof(struct memory_access));
+		if (access->array == NULL) {
+			fprintf(stderr, "cannot realloc struct memory_access access->array\n");
+			exit(EXIT_FAILURE);
+		}
 	}
 	access->array[access->num].start = start;
 	access->array[access->num].stop = stop;
@@ -1602,6 +1606,11 @@ void add_memory_page(vm_mngr_t* vm_mngr, struct memory_page_node* mpn_a)
 	vm_mngr->memory_pages_array = realloc(vm_mngr->memory_pages_array,
 					      sizeof(struct memory_page_node) *
 					      (vm_mngr->memory_pages_number+1));
+	if (vm_mngr->memory_pages_array == NULL) {
+		fprintf(stderr, "cannot realloc struct memory_page_node vm_mngr->memory_pages_array\n");
+		exit(EXIT_FAILURE);
+	}
+
 
 	memmove(&vm_mngr->memory_pages_array[i+1],
 		&vm_mngr->memory_pages_array[i],
@@ -1629,8 +1638,8 @@ char* dump(vm_mngr_t* vm_mngr)
 
 	buf_final = malloc(total_len);
 	if (buf_final == NULL) {
-		fprintf(stderr, "Error: cannot alloc\n");
-		exit(0);
+		fprintf(stderr, "Error: cannot alloc char* buf_final\n");
+		exit(EXIT_FAILURE);
 	}
 	strcpy(buf_final, intro);
 	for (i=0; i< vm_mngr->memory_pages_number; i++) {
@@ -1653,8 +1662,8 @@ char* dump(vm_mngr_t* vm_mngr)
 		total_len += length + 1 + 1;
 		buf_final = realloc(buf_final, total_len);
 		if (buf_final == NULL) {
-			fprintf(stderr, "Error: cannot alloc\n");
-			exit(0);
+			fprintf(stderr, "cannot realloc char* buf_final\n");
+			exit(EXIT_FAILURE);
 		}
 		strcat(buf_final, buf);
 	}