@@ -218,14 +218,12 @@ scram_exchange(void *opaq, char *input, int inputlen,
218
218
{
219
219
if (inputlen == 0 )
220
220
{
221
- appendPQExpBufferStr (& conn -> errorMessage ,
222
- libpq_gettext ("malformed SCRAM message (empty message)\n" ));
221
+ libpq_append_conn_error (conn , "malformed SCRAM message (empty message)" );
223
222
goto error ;
224
223
}
225
224
if (inputlen != strlen (input ))
226
225
{
227
- appendPQExpBufferStr (& conn -> errorMessage ,
228
- libpq_gettext ("malformed SCRAM message (length mismatch)\n" ));
226
+ libpq_append_conn_error (conn , "malformed SCRAM message (length mismatch)" );
229
227
goto error ;
230
228
}
231
229
}
@@ -268,24 +266,21 @@ scram_exchange(void *opaq, char *input, int inputlen,
268
266
*/
269
267
if (!verify_server_signature (state , success , & errstr ))
270
268
{
271
- appendPQExpBuffer (& conn -> errorMessage ,
272
- libpq_gettext ("could not verify server signature: %s\n" ), errstr );
269
+ libpq_append_conn_error (conn , "could not verify server signature: %s" , errstr );
273
270
goto error ;
274
271
}
275
272
276
273
if (!* success )
277
274
{
278
- appendPQExpBufferStr (& conn -> errorMessage ,
279
- libpq_gettext ("incorrect server signature\n" ));
275
+ libpq_append_conn_error (conn , "incorrect server signature" );
280
276
}
281
277
* done = true;
282
278
state -> state = FE_SCRAM_FINISHED ;
283
279
break ;
284
280
285
281
default :
286
282
/* shouldn't happen */
287
- appendPQExpBufferStr (& conn -> errorMessage ,
288
- libpq_gettext ("invalid SCRAM exchange state\n" ));
283
+ libpq_append_conn_error (conn , "invalid SCRAM exchange state" );
289
284
goto error ;
290
285
}
291
286
return ;
@@ -311,18 +306,18 @@ read_attr_value(char **input, char attr, PQExpBuffer errorMessage)
311
306
312
307
if (* begin != attr )
313
308
{
314
- appendPQExpBuffer (errorMessage ,
315
- libpq_gettext ( "malformed SCRAM message (attribute \"%c\" expected)\n" ) ,
316
- attr );
309
+ libpq_append_error (errorMessage ,
310
+ "malformed SCRAM message (attribute \"%c\" expected)" ,
311
+ attr );
317
312
return NULL ;
318
313
}
319
314
begin ++ ;
320
315
321
316
if (* begin != '=' )
322
317
{
323
- appendPQExpBuffer (errorMessage ,
324
- libpq_gettext ( "malformed SCRAM message (expected character \"=\" for attribute \"%c\")\n" ) ,
325
- attr );
318
+ libpq_append_error (errorMessage ,
319
+ "malformed SCRAM message (expected character \"=\" for attribute \"%c\")" ,
320
+ attr );
326
321
return NULL ;
327
322
}
328
323
begin ++ ;
@@ -361,8 +356,7 @@ build_client_first_message(fe_scram_state *state)
361
356
*/
362
357
if (!pg_strong_random (raw_nonce , SCRAM_RAW_NONCE_LEN ))
363
358
{
364
- appendPQExpBufferStr (& conn -> errorMessage ,
365
- libpq_gettext ("could not generate nonce\n" ));
359
+ libpq_append_conn_error (conn , "could not generate nonce" );
366
360
return NULL ;
367
361
}
368
362
@@ -371,16 +365,14 @@ build_client_first_message(fe_scram_state *state)
371
365
state -> client_nonce = malloc (encoded_len + 1 );
372
366
if (state -> client_nonce == NULL )
373
367
{
374
- appendPQExpBufferStr (& conn -> errorMessage ,
375
- libpq_gettext ("out of memory\n" ));
368
+ libpq_append_conn_error (conn , "out of memory" );
376
369
return NULL ;
377
370
}
378
371
encoded_len = pg_b64_encode (raw_nonce , SCRAM_RAW_NONCE_LEN ,
379
372
state -> client_nonce , encoded_len );
380
373
if (encoded_len < 0 )
381
374
{
382
- appendPQExpBufferStr (& conn -> errorMessage ,
383
- libpq_gettext ("could not encode nonce\n" ));
375
+ libpq_append_conn_error (conn , "could not encode nonce" );
384
376
return NULL ;
385
377
}
386
378
state -> client_nonce [encoded_len ] = '\0' ;
@@ -446,8 +438,7 @@ build_client_first_message(fe_scram_state *state)
446
438
447
439
oom_error :
448
440
termPQExpBuffer (& buf );
449
- appendPQExpBufferStr (& conn -> errorMessage ,
450
- libpq_gettext ("out of memory\n" ));
441
+ libpq_append_conn_error (conn , "out of memory" );
451
442
return NULL ;
452
443
}
453
444
@@ -569,9 +560,7 @@ build_client_final_message(fe_scram_state *state)
569
560
client_proof , & errstr ))
570
561
{
571
562
termPQExpBuffer (& buf );
572
- appendPQExpBuffer (& conn -> errorMessage ,
573
- libpq_gettext ("could not calculate client proof: %s\n" ),
574
- errstr );
563
+ libpq_append_conn_error (conn , "could not calculate client proof: %s" , errstr );
575
564
return NULL ;
576
565
}
577
566
@@ -586,8 +575,7 @@ build_client_final_message(fe_scram_state *state)
586
575
if (encoded_len < 0 )
587
576
{
588
577
termPQExpBuffer (& buf );
589
- appendPQExpBufferStr (& conn -> errorMessage ,
590
- libpq_gettext ("could not encode client proof\n" ));
578
+ libpq_append_conn_error (conn , "could not encode client proof" );
591
579
return NULL ;
592
580
}
593
581
buf .len += encoded_len ;
@@ -602,8 +590,7 @@ build_client_final_message(fe_scram_state *state)
602
590
603
591
oom_error :
604
592
termPQExpBuffer (& buf );
605
- appendPQExpBufferStr (& conn -> errorMessage ,
606
- libpq_gettext ("out of memory\n" ));
593
+ libpq_append_conn_error (conn , "out of memory" );
607
594
return NULL ;
608
595
}
609
596
@@ -623,8 +610,7 @@ read_server_first_message(fe_scram_state *state, char *input)
623
610
state -> server_first_message = strdup (input );
624
611
if (state -> server_first_message == NULL )
625
612
{
626
- appendPQExpBufferStr (& conn -> errorMessage ,
627
- libpq_gettext ("out of memory\n" ));
613
+ libpq_append_conn_error (conn , "out of memory" );
628
614
return false;
629
615
}
630
616
@@ -641,16 +627,14 @@ read_server_first_message(fe_scram_state *state, char *input)
641
627
if (strlen (nonce ) < strlen (state -> client_nonce ) ||
642
628
memcmp (nonce , state -> client_nonce , strlen (state -> client_nonce )) != 0 )
643
629
{
644
- appendPQExpBufferStr (& conn -> errorMessage ,
645
- libpq_gettext ("invalid SCRAM response (nonce mismatch)\n" ));
630
+ libpq_append_conn_error (conn , "invalid SCRAM response (nonce mismatch)" );
646
631
return false;
647
632
}
648
633
649
634
state -> nonce = strdup (nonce );
650
635
if (state -> nonce == NULL )
651
636
{
652
- appendPQExpBufferStr (& conn -> errorMessage ,
653
- libpq_gettext ("out of memory\n" ));
637
+ libpq_append_conn_error (conn , "out of memory" );
654
638
return false;
655
639
}
656
640
@@ -664,8 +648,7 @@ read_server_first_message(fe_scram_state *state, char *input)
664
648
state -> salt = malloc (decoded_salt_len );
665
649
if (state -> salt == NULL )
666
650
{
667
- appendPQExpBufferStr (& conn -> errorMessage ,
668
- libpq_gettext ("out of memory\n" ));
651
+ libpq_append_conn_error (conn , "out of memory" );
669
652
return false;
670
653
}
671
654
state -> saltlen = pg_b64_decode (encoded_salt ,
@@ -674,8 +657,7 @@ read_server_first_message(fe_scram_state *state, char *input)
674
657
decoded_salt_len );
675
658
if (state -> saltlen < 0 )
676
659
{
677
- appendPQExpBufferStr (& conn -> errorMessage ,
678
- libpq_gettext ("malformed SCRAM message (invalid salt)\n" ));
660
+ libpq_append_conn_error (conn , "malformed SCRAM message (invalid salt)" );
679
661
return false;
680
662
}
681
663
@@ -688,14 +670,12 @@ read_server_first_message(fe_scram_state *state, char *input)
688
670
state -> iterations = strtol (iterations_str , & endptr , 10 );
689
671
if (* endptr != '\0' || state -> iterations < 1 )
690
672
{
691
- appendPQExpBufferStr (& conn -> errorMessage ,
692
- libpq_gettext ("malformed SCRAM message (invalid iteration count)\n" ));
673
+ libpq_append_conn_error (conn , "malformed SCRAM message (invalid iteration count)" );
693
674
return false;
694
675
}
695
676
696
677
if (* input != '\0' )
697
- appendPQExpBufferStr (& conn -> errorMessage ,
698
- libpq_gettext ("malformed SCRAM message (garbage at end of server-first-message)\n" ));
678
+ libpq_append_conn_error (conn , "malformed SCRAM message (garbage at end of server-first-message)" );
699
679
700
680
return true;
701
681
}
@@ -714,8 +694,7 @@ read_server_final_message(fe_scram_state *state, char *input)
714
694
state -> server_final_message = strdup (input );
715
695
if (!state -> server_final_message )
716
696
{
717
- appendPQExpBufferStr (& conn -> errorMessage ,
718
- libpq_gettext ("out of memory\n" ));
697
+ libpq_append_conn_error (conn , "out of memory" );
719
698
return false;
720
699
}
721
700
@@ -730,9 +709,8 @@ read_server_final_message(fe_scram_state *state, char *input)
730
709
/* read_attr_value() has appended an error message */
731
710
return false;
732
711
}
733
- appendPQExpBuffer (& conn -> errorMessage ,
734
- libpq_gettext ("error received from server in SCRAM exchange: %s\n" ),
735
- errmsg );
712
+ libpq_append_conn_error (conn , "error received from server in SCRAM exchange: %s" ,
713
+ errmsg );
736
714
return false;
737
715
}
738
716
@@ -746,15 +724,13 @@ read_server_final_message(fe_scram_state *state, char *input)
746
724
}
747
725
748
726
if (* input != '\0' )
749
- appendPQExpBufferStr (& conn -> errorMessage ,
750
- libpq_gettext ("malformed SCRAM message (garbage at end of server-final-message)\n" ));
727
+ libpq_append_conn_error (conn , "malformed SCRAM message (garbage at end of server-final-message)" );
751
728
752
729
server_signature_len = pg_b64_dec_len (strlen (encoded_server_signature ));
753
730
decoded_server_signature = malloc (server_signature_len );
754
731
if (!decoded_server_signature )
755
732
{
756
- appendPQExpBufferStr (& conn -> errorMessage ,
757
- libpq_gettext ("out of memory\n" ));
733
+ libpq_append_conn_error (conn , "out of memory" );
758
734
return false;
759
735
}
760
736
@@ -765,8 +741,7 @@ read_server_final_message(fe_scram_state *state, char *input)
765
741
if (server_signature_len != SCRAM_KEY_LEN )
766
742
{
767
743
free (decoded_server_signature );
768
- appendPQExpBufferStr (& conn -> errorMessage ,
769
- libpq_gettext ("malformed SCRAM message (invalid server signature)\n" ));
744
+ libpq_append_conn_error (conn , "malformed SCRAM message (invalid server signature)" );
770
745
return false;
771
746
}
772
747
memcpy (state -> ServerSignature , decoded_server_signature , SCRAM_KEY_LEN );
0 commit comments