Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.openwrt.org/project/libubox.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2023-12-04 14:02:52 +0300
committerFelix Fietkau <nbd@nbd.name>2023-12-04 15:24:50 +0300
commitd27acfe416d67f9425d40b5e758949cd7ff9acfa (patch)
tree5aa209818346965617a195c0b8474bd6c5ecd410
parent40acbe34632b8e4e860fe41bb14ab5d7d5c9cfe9 (diff)
udebug: add more checks for uninitialized buffers
Simplifies and fixes error handling Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--udebug.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/udebug.c b/udebug.c
index 16beefd..0d8d0d4 100644
--- a/udebug.c
+++ b/udebug.c
@@ -460,11 +460,11 @@ int udebug_buf_init(struct udebug_buf *buf, size_t entries, size_t size)
buf->head_size = head_size;
buf->data_size = size;
buf->ring_size = entries;
- buf->fd = fd;
if (__udebug_buf_map(buf))
goto err_close;
+ buf->fd = fd;
buf->hdr->ring_size = entries;
buf->hdr->data_size = size;
@@ -545,8 +545,12 @@ void *udebug_entry_append(struct udebug_buf *buf, const void *data, uint32_t len
uint16_t udebug_entry_trim(struct udebug_buf *buf, uint16_t len)
{
struct udebug_hdr *hdr = buf->hdr;
- struct udebug_ptr *ptr = udebug_ring_ptr(hdr, hdr->head);
+ struct udebug_ptr *ptr;
+
+ if (!hdr)
+ return 0;
+ ptr = udebug_ring_ptr(hdr, hdr->head);
if (len)
ptr->len -= len;
@@ -556,8 +560,12 @@ uint16_t udebug_entry_trim(struct udebug_buf *buf, uint16_t len)
void udebug_entry_set_length(struct udebug_buf *buf, uint16_t len)
{
struct udebug_hdr *hdr = buf->hdr;
- struct udebug_ptr *ptr = udebug_ring_ptr(hdr, hdr->head);
+ struct udebug_ptr *ptr;
+
+ if (!hdr)
+ return;
+ ptr = udebug_ring_ptr(hdr, hdr->head);
ptr->len = len;
}
@@ -608,10 +616,15 @@ out:
void udebug_entry_add(struct udebug_buf *buf)
{
struct udebug_hdr *hdr = buf->hdr;
- struct udebug_ptr *ptr = udebug_ring_ptr(hdr, hdr->head);
+ struct udebug_ptr *ptr;
uint32_t notify;
uint8_t *data;
+ if (!hdr)
+ return;
+
+ ptr = udebug_ring_ptr(hdr, hdr->head);
+
/* ensure strings are always 0-terminated */
data = udebug_buf_ptr(buf, ptr->start + ptr->len);
*data = 0;
@@ -685,6 +698,9 @@ __udebug_buf_add(struct udebug *ctx, struct udebug_buf *buf)
int udebug_buf_add(struct udebug *ctx, struct udebug_buf *buf,
const struct udebug_buf_meta *meta)
{
+ if (!buf->hdr)
+ return -1;
+
list_add_tail(&buf->list, &ctx->local_rings);
buf->ctx = ctx;
buf->meta = meta;