From 65504b747f3c217dfa91297db6ea219924a3fa8a Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 23 Jul 2024 09:13:48 +0200 Subject: [PATCH] Replace remaining strtok() with strtok_r() for thread-safety in the server in the future Reviewed-by: Kyotaro Horiguchi Reviewed-by: David Steele Discussion: https://www.postgresql.org/message-id/flat/79692bf9-17d3-41e6-b9c9-fc8c3944222a@eisentraut.org --- src/backend/utils/misc/tzparser.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/backend/utils/misc/tzparser.c b/src/backend/utils/misc/tzparser.c index 21fd866d6d..96cc3912e5 100644 --- a/src/backend/utils/misc/tzparser.c +++ b/src/backend/utils/misc/tzparser.c @@ -97,6 +97,7 @@ validateTzEntry(tzEntry *tzentry) static bool splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry) { + char *brkl; char *abbrev; char *offset; char *offset_endptr; @@ -106,7 +107,7 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry) tzentry->lineno = lineno; tzentry->filename = filename; - abbrev = strtok(line, WHITESPACE); + abbrev = strtok_r(line, WHITESPACE, &brkl); if (!abbrev) { GUC_check_errmsg("missing time zone abbreviation in time zone file \"%s\", line %d", @@ -115,7 +116,7 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry) } tzentry->abbrev = pstrdup(abbrev); - offset = strtok(NULL, WHITESPACE); + offset = strtok_r(NULL, WHITESPACE, &brkl); if (!offset) { GUC_check_errmsg("missing time zone offset in time zone file \"%s\", line %d", @@ -135,11 +136,11 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry) return false; } - is_dst = strtok(NULL, WHITESPACE); + is_dst = strtok_r(NULL, WHITESPACE, &brkl); if (is_dst && pg_strcasecmp(is_dst, "D") == 0) { tzentry->is_dst = true; - remain = strtok(NULL, WHITESPACE); + remain = strtok_r(NULL, WHITESPACE, &brkl); } else { @@ -158,7 +159,7 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry) tzentry->zone = pstrdup(offset); tzentry->offset = 0 * SECS_PER_HOUR; tzentry->is_dst = false; - remain = strtok(NULL, WHITESPACE); + remain = strtok_r(NULL, WHITESPACE, &brkl); } if (!remain) /* no more non-whitespace chars */ @@ -394,8 +395,9 @@ ParseTzFile(const char *filename, int depth, { /* pstrdup so we can use filename in result data structure */ char *includeFile = pstrdup(line + strlen("@INCLUDE")); + char *brki; - includeFile = strtok(includeFile, WHITESPACE); + includeFile = strtok_r(includeFile, WHITESPACE, &brki); if (!includeFile || !*includeFile) { GUC_check_errmsg("@INCLUDE without file name in time zone file \"%s\", line %d",