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:
authorMatthias Schiffer <mschiffer@universe-factory.net>2016-06-21 18:19:10 +0300
committerFelix Fietkau <nbd@nbd.name>2016-06-26 13:53:51 +0300
commit1f019ceea1ed39286e6bccfb3ff936c22fe0f7c0 (patch)
tree92ec3e71ca90b1bb12ff930ac1b7abfa8c1d0e07 /blobmsg.c
parentc2f2c47f3e9a2d709ec82a79f6fadd3124c18781 (diff)
Fix various memory management issues
Consistently handle allocation failures. Some functions are changed to return bool or int instead of void to allow returning an error. Also fix a buffer size miscalculation in lua/uloop and use _exit() instead of exit() on errors after forking. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Diffstat (limited to 'blobmsg.c')
-rw-r--r--blobmsg.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/blobmsg.c b/blobmsg.c
index 80b984a..1e93376 100644
--- a/blobmsg.c
+++ b/blobmsg.c
@@ -227,29 +227,38 @@ blobmsg_open_nested(struct blob_buf *buf, const char *name, bool array)
return (void *)offset;
}
-void
+int
blobmsg_vprintf(struct blob_buf *buf, const char *name, const char *format, va_list arg)
{
va_list arg2;
char cbuf;
- int len;
+ char *sbuf;
+ int len, ret;
va_copy(arg2, arg);
len = vsnprintf(&cbuf, sizeof(cbuf), format, arg2);
va_end(arg2);
- vsprintf(blobmsg_alloc_string_buffer(buf, name, len + 1), format, arg);
+ sbuf = blobmsg_alloc_string_buffer(buf, name, len + 1);
+ if (!sbuf)
+ return -1;
+ ret = vsprintf(sbuf, format, arg);
blobmsg_add_string_buffer(buf);
+
+ return ret;
}
-void
+int
blobmsg_printf(struct blob_buf *buf, const char *name, const char *format, ...)
{
va_list ap;
+ int ret;
va_start(ap, format);
- blobmsg_vprintf(buf, name, format, ap);
+ ret = blobmsg_vprintf(buf, name, format, ap);
va_end(ap);
+
+ return ret;
}
void *
@@ -278,7 +287,8 @@ blobmsg_realloc_string_buffer(struct blob_buf *buf, unsigned int maxlen)
if (required <= 0)
goto out;
- blob_buf_grow(buf, required);
+ if (!blob_buf_grow(buf, required))
+ return NULL;
attr = blob_next(buf->head);
out: