]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
json: use strtok_r() instead of strtok()
authorThomas Haller <thaller@redhat.com>
Fri, 18 Aug 2023 14:33:21 +0000 (16:33 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 1 Sep 2025 20:37:01 +0000 (22:37 +0200)
commit 4646d656466b1f05bd765bbfb4d6d7bf1529bdbd upstream.

strtok_r() is probably(?) everywhere available where we care.
Use it. It is thread-safe, and libnftables shouldn't make
assumptions about what other threads of the process are doing.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
src/json.c

index dc6c03b5e857fcf2efb9f3bd4e830473a8347fe3..dbcbd5b02f5bc96ce3ae59ae7d31d3806a3a582e 100644 (file)
@@ -87,8 +87,9 @@ static json_t *set_dtype_json(const struct expr *key)
 {
        char *namedup = xstrdup(key->dtype->name), *tok;
        json_t *root = NULL;
+       char *tok_safe;
 
-       tok = strtok(namedup, " .");
+       tok = strtok_r(namedup, " .", &tok_safe);
        while (tok) {
                json_t *jtok = json_string(tok);
                if (!root)
@@ -97,7 +98,7 @@ static json_t *set_dtype_json(const struct expr *key)
                        root = nft_json_pack("[o, o]", root, jtok);
                else
                        json_array_append_new(root, jtok);
-               tok = strtok(NULL, " .");
+               tok = strtok_r(NULL, " .", &tok_safe);
        }
        xfree(namedup);
        return root;