@@ -31,6 +31,8 @@ typedef struct pe_test_config
31
31
int failure_count ;
32
32
} pe_test_config ;
33
33
34
+ #define NEVER_ACCESS_STR "\xff never-to-be-touched"
35
+
34
36
35
37
/*
36
38
* An escape function to be tested by this test.
@@ -86,6 +88,82 @@ static const PsqlScanCallbacks test_scan_callbacks = {
86
88
};
87
89
88
90
91
+ /*
92
+ * Print the string into buf, making characters outside of plain ascii
93
+ * somewhat easier to recognize.
94
+ *
95
+ * The output format could stand to be improved significantly, it's not at all
96
+ * unambiguous.
97
+ */
98
+ static void
99
+ escapify (PQExpBuffer buf , const char * str , size_t len )
100
+ {
101
+ for (size_t i = 0 ; i < len ; i ++ )
102
+ {
103
+ char c = * str ;
104
+
105
+ if (c == '\n' )
106
+ appendPQExpBufferStr (buf , "\\n" );
107
+ else if (c == '\0' )
108
+ appendPQExpBufferStr (buf , "\\0" );
109
+ else if (c < ' ' || c > '~' )
110
+ appendPQExpBuffer (buf , "\\x%2x" , (uint8_t ) c );
111
+ else
112
+ appendPQExpBufferChar (buf , c );
113
+ str ++ ;
114
+ }
115
+ }
116
+
117
+ static void
118
+ report_result (pe_test_config * tc ,
119
+ bool success ,
120
+ const char * testname ,
121
+ const char * details ,
122
+ const char * subname ,
123
+ const char * resultdesc )
124
+ {
125
+ int test_id = ++ tc -> test_count ;
126
+ bool print_details = true;
127
+ bool print_result = true;
128
+
129
+ if (success )
130
+ {
131
+ if (tc -> verbosity <= 0 )
132
+ print_details = false;
133
+ if (tc -> verbosity < 0 )
134
+ print_result = false;
135
+ }
136
+ else
137
+ tc -> failure_count ++ ;
138
+
139
+ if (print_details )
140
+ printf ("%s" , details );
141
+
142
+ if (print_result )
143
+ printf ("%s %d - %s: %s: %s\n" ,
144
+ success ? "ok" : "not ok" ,
145
+ test_id , testname ,
146
+ subname ,
147
+ resultdesc );
148
+ }
149
+
150
+ /*
151
+ * Return true for encodings in which bytes in a multi-byte character look
152
+ * like valid ascii characters.
153
+ */
154
+ static bool
155
+ encoding_conflicts_ascii (int encoding )
156
+ {
157
+ /*
158
+ * We don't store this property directly anywhere, but whether an encoding
159
+ * is a client-only encoding is a good proxy.
160
+ */
161
+ if (encoding > PG_ENCODING_BE_LAST )
162
+ return true;
163
+ return false;
164
+ }
165
+
166
+
89
167
static bool
90
168
escape_literal (PGconn * conn , PQExpBuffer target ,
91
169
const char * unescaped , size_t unescaped_len ,
@@ -383,81 +461,6 @@ static pe_test_vector pe_test_vectors[] =
383
461
};
384
462
385
463
386
- /*
387
- * Print the string into buf, making characters outside of plain ascii
388
- * somewhat easier to recognize.
389
- *
390
- * The output format could stand to be improved significantly, it's not at all
391
- * unambiguous.
392
- */
393
- static void
394
- escapify (PQExpBuffer buf , const char * str , size_t len )
395
- {
396
- for (size_t i = 0 ; i < len ; i ++ )
397
- {
398
- char c = * str ;
399
-
400
- if (c == '\n' )
401
- appendPQExpBufferStr (buf , "\\n" );
402
- else if (c == '\0' )
403
- appendPQExpBufferStr (buf , "\\0" );
404
- else if (c < ' ' || c > '~' )
405
- appendPQExpBuffer (buf , "\\x%2x" , (uint8_t ) c );
406
- else
407
- appendPQExpBufferChar (buf , c );
408
- str ++ ;
409
- }
410
- }
411
-
412
- static void
413
- report_result (pe_test_config * tc ,
414
- bool success ,
415
- PQExpBuffer testname ,
416
- PQExpBuffer details ,
417
- const char * subname ,
418
- const char * resultdesc )
419
- {
420
- int test_id = ++ tc -> test_count ;
421
- bool print_details = true;
422
- bool print_result = true;
423
-
424
- if (success )
425
- {
426
- if (tc -> verbosity <= 0 )
427
- print_details = false;
428
- if (tc -> verbosity < 0 )
429
- print_result = false;
430
- }
431
- else
432
- tc -> failure_count ++ ;
433
-
434
- if (print_details )
435
- printf ("%s" , details -> data );
436
-
437
- if (print_result )
438
- printf ("%s %d - %s: %s: %s\n" ,
439
- success ? "ok" : "not ok" ,
440
- test_id , testname -> data ,
441
- subname ,
442
- resultdesc );
443
- }
444
-
445
- /*
446
- * Return true for encodings in which bytes in a multi-byte character look
447
- * like valid ascii characters.
448
- */
449
- static bool
450
- encoding_conflicts_ascii (int encoding )
451
- {
452
- /*
453
- * We don't store this property directly anywhere, but whether an encoding
454
- * is a client-only encoding is a good proxy.
455
- */
456
- if (encoding > PG_ENCODING_BE_LAST )
457
- return true;
458
- return false;
459
- }
460
-
461
464
static const char *
462
465
scan_res_s (PsqlScanResult res )
463
466
{
@@ -532,7 +535,7 @@ test_psql_parse(pe_test_config *tc, PQExpBuffer testname,
532
535
else
533
536
resdesc = "ok" ;
534
537
535
- report_result (tc , !test_fails , testname , details ,
538
+ report_result (tc , !test_fails , testname -> data , details -> data ,
536
539
"psql parse" ,
537
540
resdesc );
538
541
}
@@ -617,7 +620,6 @@ test_one_vector_escape(pe_test_config *tc, const pe_test_vector *tv, const pe_te
617
620
*/
618
621
appendBinaryPQExpBuffer (raw_buf , tv -> escape , tv -> escape_len );
619
622
620
- #define NEVER_ACCESS_STR "\xff never-to-be-touched"
621
623
if (ef -> supports_input_length )
622
624
{
623
625
/*
@@ -671,7 +673,7 @@ test_one_vector_escape(pe_test_config *tc, const pe_test_vector *tv, const pe_te
671
673
* here, but that's not available everywhere.
672
674
*/
673
675
contains_never = strstr (escape_buf -> data , NEVER_ACCESS_STR ) == NULL ;
674
- report_result (tc , contains_never , testname , details ,
676
+ report_result (tc , contains_never , testname -> data , details -> data ,
675
677
"escaped data beyond end of input" ,
676
678
contains_never ? "no" : "all secrets revealed" );
677
679
}
@@ -714,7 +716,7 @@ test_one_vector_escape(pe_test_config *tc, const pe_test_vector *tv, const pe_te
714
716
resdesc = "valid input failed to escape, due to zero byte" ;
715
717
}
716
718
717
- report_result (tc , ok , testname , details ,
719
+ report_result (tc , ok , testname -> data , details -> data ,
718
720
"input validity vs escape success" ,
719
721
resdesc );
720
722
}
@@ -744,7 +746,7 @@ test_one_vector_escape(pe_test_config *tc, const pe_test_vector *tv, const pe_te
744
746
resdesc = "invalid input produced valid output" ;
745
747
}
746
748
747
- report_result (tc , ok , testname , details ,
749
+ report_result (tc , ok , testname -> data , details -> data ,
748
750
"input and escaped encoding validity" ,
749
751
resdesc );
750
752
}
0 commit comments