use strsep instead of strtok to avoid a segfault
[project/uci.git] / util.c
diff --git a/util.c b/util.c
index bc137c3..eb50b89 100644 (file)
--- a/util.c
+++ b/util.c
@@ -97,30 +97,29 @@ int uci_parse_tuple(struct uci_context *ctx, char *str, char **package, char **s
        UCI_HANDLE_ERR(ctx);
        UCI_ASSERT(ctx, str && package && section && option);
 
-       *package = strtok(str, ".");
+       last = strchr(str, '=');
+       if (last) {
+               *last = 0;
+               last++;
+       }
+
+       *package = strsep(&str, ".");
        if (!*package || !uci_validate_name(*package))
                goto error;
 
-       last = *package;
-       *section = strtok(NULL, ".");
+       *section = strsep(&str, ".");
        if (!*section)
                goto lastval;
 
-       last = *section;
-       *option = strtok(NULL, ".");
+       *option = strsep(&str, ".");
        if (!*option)
                goto lastval;
 
-       last = *option;
-
 lastval:
-       last = strchr(last, '=');
        if (last) {
                if (!value)
                        goto error;
 
-               *last = 0;
-               last++;
                if (!*last)
                        goto error;
                *value = last;