@@ -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 )));
199200got_verifier = false;
200201}
201202}
@@ -283,11 +284,13 @@ pg_be_scram_exchange(void *opaq, char *input, int inputlen,
283284if (inputlen == 0 )
284285ereport (ERROR ,
285286(errcode (ERRCODE_PROTOCOL_VIOLATION ),
286- (errmsg ("malformed SCRAM message (empty message)" ))));
287+ errmsg ("malformed SCRAM message" ),
288+ errdetail ("The message is empty." )));
287289if (inputlen != strlen (input ))
288290ereport (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
292295switch (state -> state )
293296{
@@ -319,7 +322,8 @@ pg_be_scram_exchange(void *opaq, char *input, int inputlen,
319322if (!verify_final_nonce (state ))
320323ereport (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 */
393397if (!pg_backend_random (saltbuf ,SCRAM_DEFAULT_SALT_LEN ))
394- {
395- ereport (LOG ,
398+ ereport (ERROR ,
396399(errcode (ERRCODE_INTERNAL_ERROR ),
397400errmsg ("could not generate random salt" )));
398- if (prep_password )
399- pfree (prep_password );
400- return NULL ;
401- }
402401
403402result = scram_build_verifier (saltbuf ,SCRAM_DEFAULT_SALT_LEN ,
404403SCRAM_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 )));
439439return false;
440440}
441441
442442salt = palloc (pg_b64_dec_len (strlen (encoded_salt )));
443443saltlen = pg_b64_decode (encoded_salt ,strlen (encoded_salt ),salt );
444444if (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 )));
447448return false;
448449}
449450
@@ -582,14 +583,16 @@ read_attr_value(char **input, char attr)
582583if (* begin != attr )
583584ereport (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 ))));
587589begin ++ ;
588590
589591if (* begin != '=' )
590592ereport (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 )));
593596begin ++ ;
594597
595598end = begin ;
@@ -669,16 +672,18 @@ read_any_attr(char **input, char *attr_p)
669672 (attr >='a' && attr <='z' )))
670673ereport (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 ))));
674678if (attr_p )
675679* attr_p = attr ;
676680begin ++ ;
677681
678682if (* begin != '=' )
679683ereport (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 )));
682687begin ++ ;
683688
684689end = begin ;
@@ -795,14 +800,16 @@ read_client_first_message(scram_state *state, char *input)
795800default :
796801ereport (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}
801807if (* input != ',' )
802808ereport (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 ))));
806813input ++ ;
807814
808815/*
@@ -815,8 +822,9 @@ read_client_first_message(scram_state *state, char *input)
815822if (* input != ',' )
816823ereport (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 ))));
820828input ++ ;
821829
822830state -> client_first_message_bare = pstrdup (input );
@@ -831,7 +839,7 @@ read_client_first_message(scram_state *state, char *input)
831839if (* input == 'm' )
832840ereport (ERROR ,
833841(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
834- errmsg ("client requiresmandatory SCRAM extension" )));
842+ errmsg ("client requiresan 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)
960968int encoded_len ;
961969
962970if (!pg_backend_random (raw_nonce ,SCRAM_RAW_NONCE_LEN ))
963- ereport (COMMERROR ,
971+ ereport (ERROR ,
964972(errcode (ERRCODE_INTERNAL_ERROR ),
965973errmsg ("could not generate random nonce" )));
966974
@@ -1044,14 +1052,16 @@ read_client_final_message(scram_state *state, char *input)
10441052if (pg_b64_decode (value ,strlen (value ),client_proof )!= SCRAM_KEY_LEN )
10451053ereport (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." )));
10481057memcpy (state -> ClientProof ,client_proof ,SCRAM_KEY_LEN );
10491058pfree (client_proof );
10501059
10511060if (* p != '\0' )
10521061ereport (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
10561066state -> client_final_message_without_proof = palloc (proof - begin + 1 );
10571067memcpy (state -> client_final_message_without_proof ,input ,proof - begin );