Skip to content

Commit 5db049f

Browse files
committed
alter realloc logic to allocate and lock new segment with memory security on
1 parent 3399ace commit 5db049f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/crypto_impl.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,20 @@ static void sqlcipher_mem_free(void *p) {
9595
default_mem_methods.xFree(p);
9696
}
9797
static void *sqlcipher_mem_realloc(void *p, int n) {
98-
return default_mem_methods.xRealloc(p, n);
98+
void *new = NULL;
99+
if(mem_security_on) {
100+
new = sqlcipher_mem_malloc(n);
101+
if(new == NULL) {
102+
return NULL;
103+
}
104+
memcpy(new, p, n);
105+
sqlcipher_mem_free(p);
106+
return new;
107+
} else {
108+
return default_mem_methods.xRealloc(p, n);
109+
}
99110
}
111+
100112
static int sqlcipher_mem_roundup(int n) {
101113
return default_mem_methods.xRoundup(n);
102114
}

0 commit comments

Comments
 (0)