* [PATCH] json: use strtok_r() instead of strtok()
@ 2023-08-18 14:33 Thomas Haller
  2023-08-18 14:53 ` Florian Westphal
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Haller @ 2023-08-18 14:33 UTC (permalink / raw)
  To: NetFilter; +Cc: 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.
Signed-off-by: Thomas Haller <thaller@redhat.com>
---
 src/json.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/json.c b/src/json.c
index a119dfc4f1eb..366c0edf485d 100644
--- a/src/json.c
+++ b/src/json.c
@@ -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;
-- 
2.41.0
^ permalink raw reply related	[flat|nested] 2+ messages in thread
* Re: [PATCH] json: use strtok_r() instead of strtok()
  2023-08-18 14:33 [PATCH] json: use strtok_r() instead of strtok() Thomas Haller
@ 2023-08-18 14:53 ` Florian Westphal
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Westphal @ 2023-08-18 14:53 UTC (permalink / raw)
  To: Thomas Haller; +Cc: NetFilter
Thomas Haller <thaller@redhat.com> wrote:
> 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.
^ permalink raw reply	[flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-18 14:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-18 14:33 [PATCH] json: use strtok_r() instead of strtok() Thomas Haller
2023-08-18 14:53 ` Florian Westphal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).