Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 24a36f9

Browse files
committed
Fix strsep() use for SCRAM secrets parsing
The previous code (from commit 5d2e1cc) did not detect end of string correctly, so it would fail to error out if fewer than the expected number of fields were present, which could then later lead to a crash when NULL string pointers are accessed. Reported-by: Alexander Lakhin <exclusion@gmail.com> Reported-by: Ranier Vilela <ranier.vf@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/79692bf9-17d3-41e6-b9c9-fc8c3944222a@eisentraut.org
1 parent 9272bde commit 24a36f9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/backend/libpq/auth-scram.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,17 @@ parse_scram_secret(const char *secret, int *iterations,
608608
* SCRAM-SHA-256$<iterations>:<salt>$<storedkey>:<serverkey>
609609
*/
610610
v = pstrdup(secret);
611-
if ((scheme_str = strsep(&v, "$")) == NULL)
611+
scheme_str = strsep(&v, "$");
612+
if (v == NULL)
612613
goto invalid_secret;
613-
if ((iterations_str = strsep(&v, ":")) == NULL)
614+
iterations_str = strsep(&v, ":");
615+
if (v == NULL)
614616
goto invalid_secret;
615-
if ((salt_str = strsep(&v, "$")) == NULL)
617+
salt_str = strsep(&v, "$");
618+
if (v == NULL)
616619
goto invalid_secret;
617-
if ((storedkey_str = strsep(&v, ":")) == NULL)
620+
storedkey_str = strsep(&v, ":");
621+
if (v == NULL)
618622
goto invalid_secret;
619623
serverkey_str = v;
620624

0 commit comments

Comments
 (0)