Skip to contentSkip to conversation

json: use strtok_r() instead of strtok()

PATCH In review Thomas Haller 2 participants 2 messages Aug 18, 2023 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 json: use strtok_r() instead of strtok()

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.

---
 src/json.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/json.c +3 -2
index a119dfc4f1eb..366c0edf485d 100644
@@ -69,8 +69,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)
@@ -79,7 +80,7 @@ static json_t *set_dtype_json(const struct expr *key)
 			root = 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;
Signature · 1 line
2.41.0
maintainer
#1 lore raw
Quoted 3 lines · Thomas Haller

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.

Agree. Applied, thanks.