ret = uci_add_list(ctx, &ptr);
break;
case CMD_REORDER:
- if (!ptr.s) {
+ if (!ptr.s || !ptr.value) {
ctx->err = UCI_ERR_NOTFOUND;
cli_perror();
return 1;
uci_alloc_parse_context(ctx);
pctx = ctx->pctx;
pctx->file = stream;
- if (*package && single) {
+ if (package && *package && single) {
pctx->package = *package;
pctx->merge = true;
}
if (dest) {
err = asprintf(dest, format,
(prefix ? prefix : ""), (prefix ? ": " : ""),
- (ctx->func ? ctx->func : ""), (ctx->func ? ": " : ""),
+ (ctx && ctx->func ? ctx->func : ""), (ctx && ctx->func ? ": " : ""),
uci_errstr[err],
error_info);
if (err < 0)
strcat(error_info, "\n");
fprintf(stderr, format,
(prefix ? prefix : ""), (prefix ? ": " : ""),
- (ctx->func ? ctx->func : ""), (ctx->func ? ": " : ""),
+ (ctx && ctx->func ? ctx->func : ""), (ctx && ctx->func ? ": " : ""),
uci_errstr[err],
error_info);
}
int uci_rename(struct uci_context *ctx, struct uci_ptr *ptr)
{
/* NB: UCI_INTERNAL use means without delta tracking */
- bool internal = ctx->internal;
+ bool internal = ctx && ctx->internal;
struct uci_element *e;
struct uci_package *p;
char *n;
int uci_add_section(struct uci_context *ctx, struct uci_package *p, const char *type, struct uci_section **res)
{
- bool internal = ctx->internal;
+ bool internal = ctx && ctx->internal;
struct uci_section *s;
UCI_HANDLE_ERR(ctx);
int uci_delete(struct uci_context *ctx, struct uci_ptr *ptr)
{
/* NB: pass on internal flag to uci_del_element */
- bool internal = ctx->internal;
+ bool internal = ctx && ctx->internal;
struct uci_package *p;
struct uci_element *e;
int uci_add_list(struct uci_context *ctx, struct uci_ptr *ptr)
{
/* NB: UCI_INTERNAL use means without delta tracking */
- bool internal = ctx->internal;
+ bool internal = ctx && ctx->internal;
struct uci_option *prev = NULL;
const char *value2 = NULL;
int uci_set(struct uci_context *ctx, struct uci_ptr *ptr)
{
/* NB: UCI_INTERNAL use means without delta tracking */
- bool internal = ctx->internal;
+ bool internal = ctx && ctx->internal;
UCI_HANDLE_ERR(ctx);
uci_expand_ptr(ctx, ptr, false);
#define UCI_HANDLE_ERR(ctx) do { \
DPRINTF("ENTER: %s\n", __func__); \
int __val = 0; \
- ctx->err = 0; \
if (!ctx) \
return UCI_ERR_INVAL; \
+ ctx->err = 0; \
if (!ctx->internal && !ctx->nested) \
__val = setjmp(ctx->trap); \
ctx->internal = false; \
network_allocate(struct uci_map *map, struct uci_sectionmap *sm, struct uci_section *s)
{
struct uci_network *p = malloc(sizeof(struct uci_network));
+ if (!p)
+ return NULL;
memset(p, 0, sizeof(struct uci_network));
return &p->map;
}
INIT_LIST_HEAD(&ifs);
ctx = uci_alloc_context();
+ if (!ctx)
+ return -1;
ucimap_init(&network_map);
if ((argc >= 2) && !strcmp(argv[1], "-s")) {
offset = (items - (*list)->size) * sizeof(union ucimap_data);
a->ptr = realloc(a->ptr, size);
+ if (!a->ptr)
+ return -ENOMEM;
+
if (offset)
memset((char *) a->ptr + offset, 0, size - offset);
new = a->ptr;