@@ -155,8 +155,8 @@ typedef struct
155155 char * logdetail ;
156156} scram_state ;
157157
158- static void read_client_first_message (scram_state * state , char * input );
159- static void read_client_final_message (scram_state * state , char * input );
158+ static void read_client_first_message (scram_state * state , const char * input );
159+ static void read_client_final_message (scram_state * state , const char * input );
160160static char * build_server_first_message (scram_state * state );
161161static char * build_server_final_message (scram_state * state );
162162static bool verify_client_proof (scram_state * state );
@@ -327,7 +327,7 @@ pg_be_scram_init(Port *port,
327327 * the client).
328328 */
329329int
330- pg_be_scram_exchange (void * opaq , char * input , int inputlen ,
330+ pg_be_scram_exchange (void * opaq , const char * input , int inputlen ,
331331 char * * output , int * outputlen , char * * logdetail )
332332{
333333 scram_state * state = (scram_state * ) opaq ;
@@ -811,11 +811,11 @@ read_any_attr(char **input, char *attr_p)
811811 * At this stage, any errors will be reported directly with ereport(ERROR).
812812 */
813813static void
814- read_client_first_message (scram_state * state , char * input )
814+ read_client_first_message (scram_state * state , const char * input )
815815{
816+ char * p = pstrdup (input );
816817 char * channel_binding_type ;
817818
818- input = pstrdup (input );
819819
820820 /*------
821821 * The syntax for the client-first-message is: (RFC 5802)
@@ -881,8 +881,8 @@ read_client_first_message(scram_state *state, char *input)
881881 * Read gs2-cbind-flag. (For details see also RFC 5802 Section 6 "Channel
882882 * Binding".)
883883 */
884- state -> cbind_flag = * input ;
885- switch (* input )
884+ state -> cbind_flag = * p ;
885+ switch (* p )
886886 {
887887 case 'n' :
888888
@@ -896,14 +896,14 @@ read_client_first_message(scram_state *state, char *input)
896896 errmsg ("malformed SCRAM message" ),
897897 errdetail ("The client selected SCRAM-SHA-256-PLUS, but the SCRAM message does not include channel binding data." )));
898898
899- input ++ ;
900- if (* input != ',' )
899+ p ++ ;
900+ if (* p != ',' )
901901 ereport (ERROR ,
902902 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
903903 errmsg ("malformed SCRAM message" ),
904904 errdetail ("Comma expected, but found character \"%s\"." ,
905- sanitize_char (* input ))));
906- input ++ ;
905+ sanitize_char (* p ))));
906+ p ++ ;
907907 break ;
908908 case 'y' :
909909
@@ -926,14 +926,14 @@ read_client_first_message(scram_state *state, char *input)
926926 errdetail ("The client supports SCRAM channel binding but thinks the server does not. "
927927 "However, this server does support channel binding." )));
928928#endif
929- input ++ ;
930- if (* input != ',' )
929+ p ++ ;
930+ if (* p != ',' )
931931 ereport (ERROR ,
932932 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
933933 errmsg ("malformed SCRAM message" ),
934934 errdetail ("Comma expected, but found character \"%s\"." ,
935- sanitize_char (* input ))));
936- input ++ ;
935+ sanitize_char (* p ))));
936+ p ++ ;
937937 break ;
938938 case 'p' :
939939
@@ -947,7 +947,7 @@ read_client_first_message(scram_state *state, char *input)
947947 errmsg ("malformed SCRAM message" ),
948948 errdetail ("The client selected SCRAM-SHA-256 without channel binding, but the SCRAM message includes channel binding data." )));
949949
950- channel_binding_type = read_attr_value (& input , 'p' );
950+ channel_binding_type = read_attr_value (& p , 'p' );
951951
952952 /*
953953 * The only channel binding type we support is
@@ -964,25 +964,25 @@ read_client_first_message(scram_state *state, char *input)
964964 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
965965 errmsg ("malformed SCRAM message" ),
966966 errdetail ("Unexpected channel-binding flag \"%s\"." ,
967- sanitize_char (* input ))));
967+ sanitize_char (* p ))));
968968 }
969969
970970 /*
971971 * Forbid optional authzid (authorization identity). We don't support it.
972972 */
973- if (* input == 'a' )
973+ if (* p == 'a' )
974974 ereport (ERROR ,
975975 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
976976 errmsg ("client uses authorization identity, but it is not supported" )));
977- if (* input != ',' )
977+ if (* p != ',' )
978978 ereport (ERROR ,
979979 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
980980 errmsg ("malformed SCRAM message" ),
981981 errdetail ("Unexpected attribute \"%s\" in client-first-message." ,
982- sanitize_char (* input ))));
983- input ++ ;
982+ sanitize_char (* p ))));
983+ p ++ ;
984984
985- state -> client_first_message_bare = pstrdup (input );
985+ state -> client_first_message_bare = pstrdup (p );
986986
987987 /*
988988 * Any mandatory extensions would go here. We don't support any.
@@ -991,7 +991,7 @@ read_client_first_message(scram_state *state, char *input)
991991 * but it can only be sent in the server-final message. We prefer to fail
992992 * immediately (which the RFC also allows).
993993 */
994- if (* input == 'm' )
994+ if (* p == 'm' )
995995 ereport (ERROR ,
996996 (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
997997 errmsg ("client requires an unsupported SCRAM extension" )));
@@ -1001,10 +1001,10 @@ read_client_first_message(scram_state *state, char *input)
10011001 * startup message instead, still it is kept around if provided as it
10021002 * proves to be useful for debugging purposes.
10031003 */
1004- state -> client_username = read_attr_value (& input , 'n' );
1004+ state -> client_username = read_attr_value (& p , 'n' );
10051005
10061006 /* read nonce and check that it is made of only printable characters */
1007- state -> client_nonce = read_attr_value (& input , 'r' );
1007+ state -> client_nonce = read_attr_value (& p , 'r' );
10081008 if (!is_scram_printable (state -> client_nonce ))
10091009 ereport (ERROR ,
10101010 (errcode (ERRCODE_PROTOCOL_VIOLATION ),
@@ -1014,8 +1014,8 @@ read_client_first_message(scram_state *state, char *input)
10141014 * There can be any number of optional extensions after this. We don't
10151015 * support any extensions, so ignore them.
10161016 */
1017- while (* input != '\0' )
1018- read_any_attr (& input , NULL );
1017+ while (* p != '\0' )
1018+ read_any_attr (& p , NULL );
10191019
10201020 /* success! */
10211021}
@@ -1144,7 +1144,7 @@ build_server_first_message(scram_state *state)
11441144 * Read and parse the final message received from client.
11451145 */
11461146static void
1147- read_client_final_message (scram_state * state , char * input )
1147+ read_client_final_message (scram_state * state , const char * input )
11481148{
11491149 char attr ;
11501150 char * channel_binding ;
0 commit comments