Fix a crash in dts+ command with empty register arenas ##debug (#172)
* Fix a crash in dts+ command with empty register arenas ##debug * Allow empty arena bytes when allocating a new arena ##reg * Added rz_mem_copy as a safe memcpy alternative ##utils Co-authored-by: Riccardo Schirone <ret2libc@users.noreply.github.com> Co-authored-by: Anton Kochkov <anton.kochkov@gmail.com> Co-authored-by: Giovanni <561184+wargio@users.noreply.github.com>
This commit is contained in:
parent
324ad1cf25
commit
e08a87ee89
5 changed files with 25 additions and 12 deletions
|
|
@ -64,7 +64,7 @@ RZ_API bool rz_debug_add_checkpoint(RzDebug *dbg) {
|
|||
for (i = 0; i < RZ_REG_TYPE_LAST; i++) {
|
||||
RzRegArena *a = dbg->reg->regset[i].arena;
|
||||
RzRegArena *b = rz_reg_arena_new (a->size);
|
||||
memcpy (b->bytes, a->bytes, b->size);
|
||||
rz_mem_copy (b->bytes, b->size, a->bytes, a->size);
|
||||
checkpoint.arena[i] = b;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ RZ_API ut8 *rz_reg_get_bytes(RzReg *reg, int type, int *size);
|
|||
RZ_API bool rz_reg_set_bytes(RzReg *reg, int type, const ut8 *buf, const int len);
|
||||
RZ_API bool rz_reg_read_regs(RzReg *reg, ut8 *buf, const int len);
|
||||
RZ_API int rz_reg_arena_set_bytes(RzReg *reg, const char *str);
|
||||
RZ_API RzRegArena *rz_reg_arena_new(int size);
|
||||
RZ_API RzRegArena *rz_reg_arena_new(size_t size);
|
||||
RZ_API void rz_reg_arena_free(RzRegArena *ra);
|
||||
RZ_API int rz_reg_fit_arena(RzReg *reg);
|
||||
RZ_API void rz_reg_arena_swap(RzReg *reg, int copy);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ RZ_API int rz_mem_eq(ut8 *a, ut8 *b, int len);
|
|||
RZ_API void rz_mem_copybits(ut8 *dst, const ut8 *src, int bits);
|
||||
RZ_API void rz_mem_copybits_delta(ut8 *dst, int doff, const ut8 *src, int soff, int bits);
|
||||
RZ_API void rz_mem_copyloop(ut8 *dest, const ut8 *orig, int dsize, int osize);
|
||||
RZ_API void *rz_mem_copy(void *dest, size_t dmax, const void *src, size_t smax);
|
||||
RZ_API void rz_mem_swaporcopy(ut8 *dest, const ut8 *src, int len, bool big_endian);
|
||||
RZ_API void rz_mem_swapendian(ut8 *dest, const ut8 *orig, int size);
|
||||
RZ_API int rz_mem_cmp_mask(const ut8 *dest, const ut8 *orig, const ut8 *mask, int len);
|
||||
|
|
|
|||
|
|
@ -166,17 +166,21 @@ RZ_API int rz_reg_fit_arena(RzReg *reg) {
|
|||
return true;
|
||||
}
|
||||
|
||||
RZ_API RzRegArena *rz_reg_arena_new(int size) {
|
||||
RZ_API RzRegArena *rz_reg_arena_new(size_t size) {
|
||||
RzRegArena *arena = RZ_NEW0 (RzRegArena);
|
||||
if (arena) {
|
||||
if (size < 1) {
|
||||
size = 1;
|
||||
}
|
||||
if (!(arena->bytes = calloc (1, size + 8))) {
|
||||
RZ_FREE (arena);
|
||||
} else {
|
||||
arena->size = size;
|
||||
}
|
||||
if (!arena) {
|
||||
RZ_LOG_ERROR ("Failed to allocate RzRegArena.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
arena->size = size;
|
||||
if (size < 1) {
|
||||
return arena;
|
||||
}
|
||||
|
||||
if (!(arena->bytes = calloc (1, size + 8))) {
|
||||
RZ_LOG_ERROR ("Failed to allocate arena bytes.\n");
|
||||
RZ_FREE (arena);
|
||||
}
|
||||
return arena;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,14 @@ RZ_API void rz_mem_copyloop(ut8 *dest, const ut8 *orig, int dsize, int osize) {
|
|||
}
|
||||
}
|
||||
|
||||
RZ_API void *rz_mem_copy(void *dest, size_t dmax, const void *src, size_t smax) {
|
||||
if (!smax || !dmax) {
|
||||
return NULL;
|
||||
}
|
||||
rz_return_val_if_fail (dest && src, NULL);
|
||||
return memcpy (dest, src, (smax < dmax) ? smax : dmax);
|
||||
}
|
||||
|
||||
RZ_API int rz_mem_cmp_mask(const ut8 *dest, const ut8 *orig, const ut8 *mask, int len) {
|
||||
ut8 *mdest = malloc (len);
|
||||
if (!mdest) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue