diff options
| author | Peter Eisentraut | 2024-07-22 13:45:46 +0000 |
|---|---|---|
| committer | Peter Eisentraut | 2024-07-22 13:45:46 +0000 |
| commit | 5d2e1cc117b38db6bb5dc2e9ae9115304571ac70 (patch) | |
| tree | af2998a07a70e5cd70aef2e99a11d749764358c4 /src/backend/libpq | |
| parent | 90c1ba52e06d0847e524b6e6c3259ab1843bb05f (diff) | |
Replace some strtok() with strsep()
strtok() considers adjacent delimiters to be one delimiter, which is
arguably the wrong behavior in some cases. Replace with strsep(),
which has the right behavior: Adjacent delimiters create an empty
token.
Affected by this are parsing of:
- Stored SCRAM secrets
("SCRAM-SHA-256$<iterations>:<salt>$<storedkey>:<serverkey>")
- ICU collation attributes
("und@colStrength=primary;colCaseLevel=yes") for ICU older than
version 54
- PG_COLORS environment variable
("error=01;31:warning=01;35:note=01;36:locus=01")
- pg_regress command-line options with comma-separated list arguments
(--dbname, --create-role) (currently only used pg_regress_ecpg)
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
Diffstat (limited to 'src/backend/libpq')
| -rw-r--r-- | src/backend/libpq/auth-scram.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/backend/libpq/auth-scram.c b/src/backend/libpq/auth-scram.c index 41619599148..03ddddc3c27 100644 --- a/src/backend/libpq/auth-scram.c +++ b/src/backend/libpq/auth-scram.c @@ -608,16 +608,15 @@ parse_scram_secret(const char *secret, int *iterations, * SCRAM-SHA-256$<iterations>:<salt>$<storedkey>:<serverkey> */ v = pstrdup(secret); - if ((scheme_str = strtok(v, "$")) == NULL) + if ((scheme_str = strsep(&v, "$")) == NULL) goto invalid_secret; - if ((iterations_str = strtok(NULL, ":")) == NULL) + if ((iterations_str = strsep(&v, ":")) == NULL) goto invalid_secret; - if ((salt_str = strtok(NULL, "$")) == NULL) + if ((salt_str = strsep(&v, "$")) == NULL) goto invalid_secret; - if ((storedkey_str = strtok(NULL, ":")) == NULL) - goto invalid_secret; - if ((serverkey_str = strtok(NULL, "")) == NULL) + if ((storedkey_str = strsep(&v, ":")) == NULL) goto invalid_secret; + serverkey_str = v; /* Parse the fields */ if (strcmp(scheme_str, "SCRAM-SHA-256") != 0) |
