mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-25 16:51:30 +00:00
Fix #22767 - Some UB when malloc(0) in RBuffer api ##crash
This commit is contained in:
parent
8644a29556
commit
ff2f2a312b
@ -159,11 +159,13 @@ R_API ut8* r_core_transform_op(RCore *core, const char *arg, char op) {
|
||||
len = xlen;
|
||||
} else { // use clipboard as key
|
||||
const ut8 *tmp = r_buf_data (core->yank_buf, &len);
|
||||
if (tmp && len > 0) {
|
||||
str = r_mem_dup (tmp, len);
|
||||
if (!str) {
|
||||
goto beach;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
len = 0;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2020 - ret2libc */
|
||||
/* radare - LGPL - Copyright 2009-2024 - ret2libc */
|
||||
|
||||
#include <r_util.h>
|
||||
|
||||
@ -35,14 +35,26 @@ static bool buf_bytes_init(RBuffer *b, const void *user) {
|
||||
priv->buf = (ut8 *)u->data_steal;
|
||||
priv->is_bufowner = u->steal;
|
||||
} else {
|
||||
#if 0
|
||||
size_t length = priv->length > 0? priv->length: 1;
|
||||
priv->buf = malloc (length);
|
||||
if (!priv->buf) {
|
||||
free (priv);
|
||||
return false;
|
||||
}
|
||||
if (priv->length > 0) {
|
||||
memmove (priv->buf, u->data, priv->length);
|
||||
}
|
||||
#else
|
||||
if (priv->length > 0) {
|
||||
priv->buf = malloc (priv->length);
|
||||
if (!priv->buf) {
|
||||
free (priv);
|
||||
return false;
|
||||
}
|
||||
if (priv->length) {
|
||||
memmove (priv->buf, u->data, priv->length);
|
||||
}
|
||||
#endif
|
||||
priv->is_bufowner = true;
|
||||
}
|
||||
b->priv = priv;
|
||||
|
@ -303,10 +303,13 @@ R_API bool r_mem_protect(void *ptr, int size, const char *prot) {
|
||||
|
||||
R_API void *r_mem_dup(const void *s, int l) {
|
||||
r_return_val_if_fail (s, NULL);
|
||||
void *d = malloc (l);
|
||||
void *d = NULL;
|
||||
if (l > 0) {
|
||||
d = malloc (l);
|
||||
if (d != NULL) {
|
||||
memcpy (d, s, l);
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user