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

Commit db1f289

Browse files
committed
Clean up some SCRAM attribute processing
Correct the comment for read_any_attr(). Give a clearer error message when parsing at the end of the string, when the client-final-message does not contain a "p" attribute (for some reason). Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://www.postgresql.org/message-id/flat/2fb8a15b-de35-682d-a77b-edcc9c52fa12%402ndquadrant.com
1 parent f8cf524 commit db1f289

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/backend/libpq/auth-scram.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,8 @@ sanitize_str(const char *s)
790790
/*
791791
* Read the next attribute and value in a SCRAM exchange message.
792792
*
793-
* Returns NULL if there is attribute.
793+
* The attribute character is set in *attr_p, the attribute value is the
794+
* return value.
794795
*/
795796
static char *
796797
read_any_attr(char **input, char *attr_p)
@@ -799,6 +800,12 @@ read_any_attr(char **input, char *attr_p)
799800
char *end;
800801
char attr = *begin;
801802

803+
if (attr == '\0')
804+
ereport(ERROR,
805+
(errcode(ERRCODE_PROTOCOL_VIOLATION),
806+
errmsg("malformed SCRAM message"),
807+
errdetail("Attribute expected, but found end of string.")));
808+
802809
/*------
803810
* attr-val = ALPHA "=" value
804811
* ;; Generic syntax of any attribute sent
@@ -1298,7 +1305,7 @@ read_client_final_message(scram_state *state, const char *input)
12981305

12991306
state->client_final_nonce = read_attr_value(&p, 'r');
13001307

1301-
/* ignore optional extensions */
1308+
/* ignore optional extensions, read until we find "p" attribute */
13021309
do
13031310
{
13041311
proof = p - 1;

0 commit comments

Comments
 (0)