about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm/tools/emul_lib/libcodenat.c18
-rw-r--r--miasm/tools/emul_lib/libcodenat.h1
-rw-r--r--miasm/tools/emul_lib/libcodenat_interface.c5
3 files changed, 22 insertions, 2 deletions
diff --git a/miasm/tools/emul_lib/libcodenat.c b/miasm/tools/emul_lib/libcodenat.c
index aedbce49..5d598f8c 100644
--- a/miasm/tools/emul_lib/libcodenat.c
+++ b/miasm/tools/emul_lib/libcodenat.c
@@ -1002,12 +1002,12 @@ struct memory_page_node * create_memory_page_node(uint64_t ad, unsigned int size
 	mpn = malloc(sizeof(*mpn));
 	if (!mpn){
 		fprintf(stderr, "cannot alloc mpn\n");
-		exit(-1);
+		return NULL;
 	}
 	p = malloc(size);
 	if (!p){
 		fprintf(stderr, "cannot alloc %d\n", size);
-		exit(-1);
+		return NULL;
 	}
 	mpn->ad = ad;
 	mpn->size = size;
@@ -1104,6 +1104,20 @@ void reset_code_bloc_pool(void)
 	code_bloc_pool_ad_max = 0;
 }
 
+int is_mpn_in_tab(struct memory_page_node* mpn_a)
+{
+	unsigned int i;
+	for (i=mpn_a->ad >> MEMORY_PAGE_POOL_MASK_BIT;
+	     i<(mpn_a->ad + mpn_a->size + PAGE_SIZE - 1)>>MEMORY_PAGE_POOL_MASK_BIT;
+	     i++){
+		if (memory_page_pool_tab[i] !=NULL){
+			return 1;
+		}
+	}
+
+	return 0;
+}
+
 void insert_mpn_in_tab(struct memory_page_node* mpn_a)
 {
 	unsigned int i;
diff --git a/miasm/tools/emul_lib/libcodenat.h b/miasm/tools/emul_lib/libcodenat.h
index d91532c0..d4047f16 100644
--- a/miasm/tools/emul_lib/libcodenat.h
+++ b/miasm/tools/emul_lib/libcodenat.h
@@ -347,6 +347,7 @@ unsigned int get_memory_page_max_address(void);
 unsigned int get_memory_page_max_user_address(void);
 
 
+int is_mpn_in_tab(struct memory_page_node* mpn_a);
 
 
 void _func_free(void);
diff --git a/miasm/tools/emul_lib/libcodenat_interface.c b/miasm/tools/emul_lib/libcodenat_interface.c
index 2bf78de3..ce402e07 100644
--- a/miasm/tools/emul_lib/libcodenat_interface.c
+++ b/miasm/tools/emul_lib/libcodenat_interface.c
@@ -348,6 +348,11 @@ PyObject* _vm_add_memory_page(PyObject *item, PyObject *access, PyObject *item_s
 
 
     mpn = create_memory_page_node(page_addr, buf_size, page_access);
+    if (mpn == NULL)
+       RAISE(PyExc_TypeError,"cannot create page");
+    if (is_mpn_in_tab(mpn))
+       RAISE(PyExc_TypeError,"known page in memory");
+
     memcpy(mpn->ad_hp, buf_data, buf_size);
     add_memory_page(mpn);