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 *
if (required <= 0)
goto out;
- blob_buf_grow(buf, required);
+ if (!blob_buf_grow(buf, required))
+ return NULL;
attr = blob_next(buf->head);
out:
void *blobmsg_realloc_string_buffer(struct blob_buf *buf, unsigned int maxlen);
void blobmsg_add_string_buffer(struct blob_buf *buf);
-void blobmsg_vprintf(struct blob_buf *buf, const char *name, const char *format, va_list arg);
-void blobmsg_printf(struct blob_buf *buf, const char *name, const char *format, ...)
+int blobmsg_vprintf(struct blob_buf *buf, const char *name, const char *format, va_list arg);
+int blobmsg_printf(struct blob_buf *buf, const char *name, const char *format, ...)
__attribute__((format(printf, 3, 4)));
static bool blobmsg_puts(struct strbuf *s, const char *c, int len)
{
+ size_t new_len;
+ char *new_buf;
+
if (len <= 0)
return true;
if (s->pos + len >= s->len) {
- s->len += 16 + len;
- s->buf = realloc(s->buf, s->len);
- if (!s->buf)
+ new_len = s->len + 16 + len;
+ new_buf = realloc(s->buf, new_len);
+ if (!new_buf)
return false;
+
+ s->len = new_len;
+ s->buf = new_buf;
}
+
memcpy(s->buf + s->pos, c, len);
s->pos += len;
return true;
{
struct strbuf s;
bool array;
+ char *ret;
s.len = blob_len(attr);
- s.buf = malloc(s.len);
s.pos = 0;
s.custom_format = cb;
s.priv = priv;
s.indent = false;
+ s.buf = malloc(s.len);
+ if (!s.buf)
+ return NULL;
+
if (indent >= 0) {
s.indent = true;
s.indent_level = indent;
return NULL;
}
- s.buf = realloc(s.buf, s.pos + 1);
- s.buf[s.pos] = 0;
+ ret = realloc(s.buf, s.pos + 1);
+ if (!ret) {
+ free(s.buf);
+ return NULL;
+ }
+
+ ret[s.pos] = 0;
- return s.buf;
+ return ret;
}
for (i = 0; environ[i]; i++);
vars = calloc(i, sizeof(*vars));
+ if (!vars) {
+ fprintf(stderr, "%m\n");
+ return -1;
+ }
for (i = 0; environ[i]; i++) {
char *c;
name_len = strlen(name) + 1;
f = calloc_a(sizeof(*f) + len, &new_name, name_len);
+ if (!f)
+ return NULL;
+
memcpy(f->data, data, len);
if (name)
f->avl.key = strcpy(new_name, name);
char c = '%';
dest = blobmsg_alloc_string_buffer(buf, name, 1);
+ if (!dest)
+ return -1;
+
next = alloca(strlen(pattern) + 1);
strcpy(next, pattern);
for (str = next; str; str = next) {
const char *cur;
- char *end;
+ char *end, *new_buf;
int cur_len = 0;
bool cur_var = var;
cur_len = end - str;
}
- dest = blobmsg_realloc_string_buffer(buf, len + cur_len + 1);
+ new_buf = blobmsg_realloc_string_buffer(buf, len + cur_len + 1);
+ if (!new_buf) {
+ /* Make eval_string return -1 */
+ var = true;
+ break;
+ }
+
+ dest = new_buf;
memcpy(dest + len, cur, cur_len);
len += cur_len;
}
return !!node;
}
-void kvlist_set(struct kvlist *kv, const char *name, const void *data)
+bool kvlist_set(struct kvlist *kv, const char *name, const void *data)
{
struct kvlist_node *node;
char *name_buf;
int len = kv->get_len(kv, data);
- kvlist_delete(kv, name);
-
node = calloc_a(sizeof(struct kvlist_node) + len,
&name_buf, strlen(name) + 1);
+ if (!node)
+ return false;
+
+ kvlist_delete(kv, name);
+
memcpy(node->data, data, len);
node->avl.key = strcpy(name_buf, name);
avl_insert(&kv->avl, &node->avl);
+
+ return true;
}
void kvlist_free(struct kvlist *kv)
void kvlist_init(struct kvlist *kv, int (*get_len)(struct kvlist *kv, const void *data));
void kvlist_free(struct kvlist *kv);
void *kvlist_get(struct kvlist *kv, const char *name);
-void kvlist_set(struct kvlist *kv, const char *name, const void *data);
+bool kvlist_set(struct kvlist *kv, const char *name, const void *data);
bool kvlist_delete(struct kvlist *kv, const char *name);
int kvlist_strlen(struct kvlist *kv, const void *data);
int argn = lua_objlen(L, -3);
int envn = lua_objlen(L, -2);
char** argp = malloc(sizeof(char*) * (argn + 2));
- char** envp = malloc(sizeof(char*) * envn + 1);
+ char** envp = malloc(sizeof(char*) * (envn + 1));
int i = 1;
+ if (!argp || !envp)
+ _exit(-1);
+
argp[0] = (char*) lua_tostring(L, -4);
for (i = 1; i <= argn; i++) {
lua_rawgeti(L, -3, i);
envp[i - 1] = NULL;
execve(*argp, argp, envp);
- exit(-1);
+ _exit(-1);
}
lua_getglobal(L, "__uloop_cb");
return -1;
buf = malloc(sizeof(*buf) + l->buffer_len + s->string_data);
+ if (!buf)
+ return -1;
+
ustream_init_buf(buf, l->buffer_len);
ustream_add_buf(l, buf);
return ustream_write_buffered(s, buf, maxlen, wr);
} else {
buf = malloc(maxlen + 1);
+ if (!buf)
+ return 0;
wr = vsnprintf(buf, maxlen + 1, format, arg);
wr = ustream_write(s, buf, wr, false);
free(buf);
return wr;
buf = malloc(maxlen + 1);
+ if (!buf)
+ return wr;
maxlen = vsnprintf(buf, maxlen + 1, format, arg);
wr = ustream_write_buffered(s, buf + wr, maxlen - wr, wr);
free(buf);
va_end(ap1);
ptr = calloc(1, alloc_len);
+ if (!ptr)
+ return NULL;
alloc_len = 0;
foreach_arg(ap, cur_addr, cur_len, &ret, len) {
*cur_addr = &ptr[alloc_len];