@@ -195,7 +195,8 @@ pg_be_scram_init(const char *username, const char *shadow_pass)
195195 * The password looked like a SCRAM verifier, but could not be
196196 * parsed.
197197 */
198- elog (LOG , "invalid SCRAM verifier for user \"%s\"" , username );
198+ ereport (LOG ,
199+ (errmsg ("invalid SCRAM verifier for user \"%s\"" , username )));
199200 got_verifier = false;
200201 }
201202 }
@@ -283,11 +284,13 @@ pg_be_scram_exchange(void *opaq, char *input, int inputlen,
283284 if (inputlen == 0 )
284285 ereport (ERROR ,
285286 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
286- (errmsg ("malformed SCRAM message (empty message)" ))));
287+ errmsg ("malformed SCRAM message" ),
288+ errdetail ("The message is empty." )));
287289 if (inputlen != strlen (input ))
288290 ereport (ERROR ,
289291 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
290- (errmsg ("malformed SCRAM message (length mismatch)" ))));
292+ errmsg ("malformed SCRAM message" ),
293+ errdetail ("Message length does not match input length." )));
291294
292295 switch (state -> state )
293296 {
@@ -319,7 +322,8 @@ pg_be_scram_exchange(void *opaq, char *input, int inputlen,
319322 if (!verify_final_nonce (state ))
320323 ereport (ERROR ,
321324 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
322- (errmsg ("invalid SCRAM response (nonce mismatch)" ))));
325+ errmsg ("invalid SCRAM response" ),
326+ errdetail ("Nonce does not match." )));
323327
324328 /*
325329 * Now check the final nonce and the client proof.
@@ -391,14 +395,9 @@ pg_be_scram_build_verifier(const char *password)
391395
392396 /* Generate random salt */
393397 if (!pg_backend_random (saltbuf , SCRAM_DEFAULT_SALT_LEN ))
394- {
395- ereport (LOG ,
398+ ereport (ERROR ,
396399 (errcode (ERRCODE_INTERNAL_ERROR ),
397400 errmsg ("could not generate random salt" )));
398- if (prep_password )
399- pfree (prep_password );
400- return NULL ;
401- }
402401
403402 result = scram_build_verifier (saltbuf , SCRAM_DEFAULT_SALT_LEN ,
404403 SCRAM_DEFAULT_ITERATIONS , password );
@@ -435,15 +434,17 @@ scram_verify_plain_password(const char *username, const char *password,
435434 /*
436435 * The password looked like a SCRAM verifier, but could not be parsed.
437436 */
438- elog (LOG , "invalid SCRAM verifier for user \"%s\"" , username );
437+ ereport (LOG ,
438+ (errmsg ("invalid SCRAM verifier for user \"%s\"" , username )));
439439 return false;
440440 }
441441
442442 salt = palloc (pg_b64_dec_len (strlen (encoded_salt )));
443443 saltlen = pg_b64_decode (encoded_salt , strlen (encoded_salt ), salt );
444444 if (saltlen == -1 )
445445 {
446- elog (LOG , "invalid SCRAM verifier for user \"%s\"" , username );
446+ ereport (LOG ,
447+ (errmsg ("invalid SCRAM verifier for user \"%s\"" , username )));
447448 return false;
448449 }
449450
@@ -582,14 +583,16 @@ read_attr_value(char **input, char attr)
582583 if (* begin != attr )
583584 ereport (ERROR ,
584585 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
585- (errmsg ("malformed SCRAM message (attribute '%c' expected, %s found)" ,
586- attr , sanitize_char (* begin )))));
586+ errmsg ("malformed SCRAM message" ),
587+ errdetail ("Expected attribute '%c' but found %s." ,
588+ attr , sanitize_char (* begin ))));
587589 begin ++ ;
588590
589591 if (* begin != '=' )
590592 ereport (ERROR ,
591593 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
592- (errmsg ("malformed SCRAM message (expected = in attr %c)" , attr ))));
594+ errmsg ("malformed SCRAM message" ),
595+ errdetail ("Expected character = for attribute %c." , attr )));
593596 begin ++ ;
594597
595598 end = begin ;
@@ -669,16 +672,18 @@ read_any_attr(char **input, char *attr_p)
669672 (attr >= 'a' && attr <= 'z' )))
670673 ereport (ERROR ,
671674 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
672- (errmsg ("malformed SCRAM message (attribute expected, invalid char %s found)" ,
673- sanitize_char (attr )))));
675+ errmsg ("malformed SCRAM message" ),
676+ errdetail ("Attribute expected, but found invalid character %s." ,
677+ sanitize_char (attr ))));
674678 if (attr_p )
675679 * attr_p = attr ;
676680 begin ++ ;
677681
678682 if (* begin != '=' )
679683 ereport (ERROR ,
680684 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
681- (errmsg ("malformed SCRAM message (expected = in attr %c)" , attr ))));
685+ errmsg ("malformed SCRAM message" ),
686+ errdetail ("Expected character = for attribute %c." , attr )));
682687 begin ++ ;
683688
684689 end = begin ;
@@ -795,14 +800,16 @@ read_client_first_message(scram_state *state, char *input)
795800 default :
796801 ereport (ERROR ,
797802 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
798- (errmsg ("malformed SCRAM message (unexpected channel-binding flag %s)" ,
799- sanitize_char (* input )))));
803+ errmsg ("malformed SCRAM message" ),
804+ errdetail ("Unexpected channel-binding flag %s." ,
805+ sanitize_char (* input ))));
800806 }
801807 if (* input != ',' )
802808 ereport (ERROR ,
803809 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
804- errmsg ("malformed SCRAM message (comma expected, got %s)" ,
805- sanitize_char (* input ))));
810+ errmsg ("malformed SCRAM message" ),
811+ errdetail ("Comma expected, but found character %s." ,
812+ sanitize_char (* input ))));
806813 input ++ ;
807814
808815 /*
@@ -815,8 +822,9 @@ read_client_first_message(scram_state *state, char *input)
815822 if (* input != ',' )
816823 ereport (ERROR ,
817824 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
818- errmsg ("malformed SCRAM message (unexpected attribute %s in client-first-message)" ,
819- sanitize_char (* input ))));
825+ errmsg ("malformed SCRAM message" ),
826+ errdetail ("Unexpected attribute %s in client-first-message." ,
827+ sanitize_char (* input ))));
820828 input ++ ;
821829
822830 state -> client_first_message_bare = pstrdup (input );
@@ -831,7 +839,7 @@ read_client_first_message(scram_state *state, char *input)
831839 if (* input == 'm' )
832840 ereport (ERROR ,
833841 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
834- errmsg ("client requires mandatory SCRAM extension" )));
842+ errmsg ("client requires an unsupported SCRAM extension" )));
835843
836844 /*
837845 * Read username. Note: this is ignored. We use the username from the
@@ -960,7 +968,7 @@ build_server_first_message(scram_state *state)
960968 int encoded_len ;
961969
962970 if (!pg_backend_random (raw_nonce , SCRAM_RAW_NONCE_LEN ))
963- ereport (COMMERROR ,
971+ ereport (ERROR ,
964972 (errcode (ERRCODE_INTERNAL_ERROR ),
965973 errmsg ("could not generate random nonce" )));
966974
@@ -1044,14 +1052,16 @@ read_client_final_message(scram_state *state, char *input)
10441052 if (pg_b64_decode (value , strlen (value ), client_proof ) != SCRAM_KEY_LEN )
10451053 ereport (ERROR ,
10461054 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
1047- (errmsg ("malformed SCRAM message (malformed proof in client-final-message" ))));
1055+ errmsg ("malformed SCRAM message" ),
1056+ errdetail ("Malformed proof in client-final-message." )));
10481057 memcpy (state -> ClientProof , client_proof , SCRAM_KEY_LEN );
10491058 pfree (client_proof );
10501059
10511060 if (* p != '\0' )
10521061 ereport (ERROR ,
10531062 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
1054- (errmsg ("malformed SCRAM message (garbage at end of client-final-message)" ))));
1063+ errmsg ("malformed SCRAM message" ),
1064+ errdetail ("Garbage found at the end of client-final-message." )));
10551065
10561066 state -> client_final_message_without_proof = palloc (proof - begin + 1 );
10571067 memcpy (state -> client_final_message_without_proof , input , proof - begin );
0 commit comments