Skip to content

Commit 65504b7

Browse files
committed
Replace remaining strtok() with strtok_r()
for thread-safety in the server in the future Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-by: David Steele <david@pgmasters.net> Discussion: https://www.postgresql.org/message-id/flat/79692bf9-17d3-41e6-b9c9-fc8c3944222a@eisentraut.org
1 parent 4d130b2 commit 65504b7

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/backend/utils/misc/tzparser.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ validateTzEntry(tzEntry *tzentry)
9797
static bool
9898
splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
9999
{
100+
char *brkl;
100101
char *abbrev;
101102
char *offset;
102103
char *offset_endptr;
@@ -106,7 +107,7 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
106107
tzentry->lineno = lineno;
107108
tzentry->filename = filename;
108109

109-
abbrev = strtok(line, WHITESPACE);
110+
abbrev = strtok_r(line, WHITESPACE, &brkl);
110111
if (!abbrev)
111112
{
112113
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)
115116
}
116117
tzentry->abbrev = pstrdup(abbrev);
117118

118-
offset = strtok(NULL, WHITESPACE);
119+
offset = strtok_r(NULL, WHITESPACE, &brkl);
119120
if (!offset)
120121
{
121122
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)
135136
return false;
136137
}
137138

138-
is_dst = strtok(NULL, WHITESPACE);
139+
is_dst = strtok_r(NULL, WHITESPACE, &brkl);
139140
if (is_dst && pg_strcasecmp(is_dst, "D") == 0)
140141
{
141142
tzentry->is_dst = true;
142-
remain = strtok(NULL, WHITESPACE);
143+
remain = strtok_r(NULL, WHITESPACE, &brkl);
143144
}
144145
else
145146
{
@@ -158,7 +159,7 @@ splitTzLine(const char *filename, int lineno, char *line, tzEntry *tzentry)
158159
tzentry->zone = pstrdup(offset);
159160
tzentry->offset = 0 * SECS_PER_HOUR;
160161
tzentry->is_dst = false;
161-
remain = strtok(NULL, WHITESPACE);
162+
remain = strtok_r(NULL, WHITESPACE, &brkl);
162163
}
163164

164165
if (!remain) /* no more non-whitespace chars */
@@ -394,8 +395,9 @@ ParseTzFile(const char *filename, int depth,
394395
{
395396
/* pstrdup so we can use filename in result data structure */
396397
char *includeFile = pstrdup(line + strlen("@INCLUDE"));
398+
char *brki;
397399

398-
includeFile = strtok(includeFile, WHITESPACE);
400+
includeFile = strtok_r(includeFile, WHITESPACE, &brki);
399401
if (!includeFile || !*includeFile)
400402
{
401403
GUC_check_errmsg("@INCLUDE without file name in time zone file \"%s\", line %d",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy