lua: always return after calling luaL_error (patch by Stanislav Fomichev)
[project/uci.git] / cli.c
diff --git a/cli.c b/cli.c
index b660273f96b397023e5f62ce3e45e329adeb1a0d..196a83ea35d42d16480bb7900c8007b8dbfb10c0 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -98,6 +98,8 @@ uci_lookup_section_ref(struct uci_section *s)
        }
        if (!ti) {
                ti = malloc(sizeof(struct uci_type_list));
+               if (!ti)
+                       return NULL;
                memset(ti, 0, sizeof(struct uci_type_list));
                ti->next = type_list;
                type_list = ti;
@@ -110,8 +112,12 @@ uci_lookup_section_ref(struct uci_section *s)
        } else {
                typestr = realloc(typestr, maxlen);
        }
-       sprintf(typestr, "@%s[%d]", ti->name, ti->idx);
+
+       if (typestr)
+               sprintf(typestr, "@%s[%d]", ti->name, ti->idx);
+
        ti->idx++;
+
        return typestr;
 }
 
@@ -444,7 +450,7 @@ static int uci_do_section_cmd(int cmd, int argc, char **argv)
                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;
@@ -627,6 +633,11 @@ int main(int argc, char **argv)
                                delimiter = optarg;
                                break;
                        case 'f':
+                               if (input != stdin) {
+                                       perror("uci");
+                                       return 1;
+                               }
+
                                input = fopen(optarg, "r");
                                if (!input) {
                                        perror("uci");