Fossil SCM

Enhance codecheck1.c to check recently added varargs functions.

drh 2020-05-28 14:20 trunk
Commit b17aba9e20d823736ed93ab6ea0fb00d140de84070d000f7fe01c05f611ac9a1
+37 -17
--- src/codecheck1.c
+++ src/codecheck1.c
@@ -343,48 +343,54 @@
343343
}
344344
345345
/*
346346
** Processing flags
347347
*/
348
-#define FMT_SQL 0x00001 /* Generates SQL text */
349
-#define FMT_HTML 0x00002 /* Generates HTML text */
350
-#define FMT_URL 0x00004 /* Generates URLs */
351
-#define FMT_SAFE 0x00008 /* Always safe for %s */
348
+#define FMT_SQL 0x00001 /* Generator for SQL text */
349
+#define FMT_HTML 0x00002 /* Generator for HTML text */
350
+#define FMT_URL 0x00004 /* Generator for URLs */
351
+#define FMT_SAFE 0x00008 /* Generator for human-readable text */
352352
353353
/*
354354
** A list of internal Fossil interfaces that take a printf-style format
355355
** string.
356356
*/
357
-struct {
357
+struct FmtFunc {
358358
const char *zFName; /* Name of the function */
359359
int iFmtArg; /* Index of format argument. Leftmost is 1. */
360360
unsigned fmtFlags; /* Processing flags */
361361
} aFmtFunc[] = {
362
- { "admin_log", 1, 0 },
362
+ { "admin_log", 1, FMT_SAFE },
363
+ { "audit_append", 3, FMT_SAFE },
364
+ { "backofficeTrace", 1, FMT_SAFE },
363365
{ "blob_append_sql", 2, FMT_SQL },
364
- { "blob_appendf", 2, 0 },
366
+ { "blob_appendf", 2, FMT_SAFE },
365367
{ "cgi_debug", 1, FMT_SAFE },
366368
{ "cgi_panic", 1, FMT_SAFE },
367369
{ "cgi_printf", 1, FMT_HTML },
370
+ { "cgi_printf_header", 1, FMT_HTML },
368371
{ "cgi_redirectf", 1, FMT_URL },
369372
{ "chref", 2, FMT_URL },
373
+ { "CX", 1, FMT_HTML },
370374
{ "db_blob", 2, FMT_SQL },
371375
{ "db_debug", 1, FMT_SQL },
372376
{ "db_double", 2, FMT_SQL },
373
- { "db_err", 1, 0 },
377
+ { "db_err", 1, FMT_SAFE },
374378
{ "db_exists", 1, FMT_SQL },
375
- { "db_get_mprintf", 2, 0 },
379
+ { "db_get_mprintf", 2, FMT_SAFE },
376380
{ "db_int", 2, FMT_SQL },
377381
{ "db_int64", 2, FMT_SQL },
378382
{ "db_multi_exec", 1, FMT_SQL },
379383
{ "db_optional_sql", 2, FMT_SQL },
380384
{ "db_prepare", 2, FMT_SQL },
381385
{ "db_prepare_ignore_error", 2, FMT_SQL },
382
- { "db_set_mprintf", 3, 0 },
386
+ { "db_set_mprintf", 3, FMT_SAFE },
383387
{ "db_static_prepare", 2, FMT_SQL },
384388
{ "db_text", 2, FMT_SQL },
385
- { "db_unset_mprintf", 2, 0 },
389
+ { "db_unset_mprintf", 2, FMT_SAFE },
390
+ { "emailerError", 2, FMT_SAFE },
391
+ { "fileedit_ajax_error", 2, FMT_SAFE },
386392
{ "form_begin", 2, FMT_URL },
387393
{ "fossil_error", 2, FMT_SAFE },
388394
{ "fossil_errorlog", 1, FMT_SAFE },
389395
{ "fossil_fatal", 1, FMT_SAFE },
390396
{ "fossil_fatal_recursive", 1, FMT_SAFE },
@@ -391,24 +397,36 @@
391397
{ "fossil_panic", 1, FMT_SAFE },
392398
{ "fossil_print", 1, FMT_SAFE },
393399
{ "fossil_trace", 1, FMT_SAFE },
394400
{ "fossil_warning", 1, FMT_SAFE },
395401
{ "href", 1, FMT_URL },
396
- { "json_new_string_f", 1, 0 },
397
- { "json_set_err", 2, 0 },
398
- { "json_warn", 2, 0 },
399
- { "mprintf", 1, 0 },
400
- { "socket_set_errmsg", 1, 0 },
401
- { "ssl_set_errmsg", 1, 0 },
402
+ { "json_new_string_f", 1, FMT_SAFE },
403
+ { "json_set_err", 2, FMT_SAFE },
404
+ { "json_warn", 2, FMT_SAFE },
405
+ { "mprintf", 1, FMT_SAFE },
406
+ { "pop3_print", 2, FMT_SAFE },
407
+ { "smtp_send_line", 2, FMT_SAFE },
408
+ { "smtp_server_send", 2, FMT_SAFE },
409
+ { "socket_set_errmsg", 1, FMT_SAFE },
410
+ { "ssl_set_errmsg", 1, FMT_SAFE },
402411
{ "style_header", 1, FMT_HTML },
403412
{ "style_js_onload", 1, FMT_HTML },
404413
{ "style_set_current_page", 1, FMT_URL },
405414
{ "style_submenu_element", 2, FMT_URL },
406415
{ "style_submenu_sql", 3, FMT_SQL },
407416
{ "webpage_error", 1, FMT_SAFE },
408417
{ "xhref", 2, FMT_URL },
409418
};
419
+
420
+/*
421
+** Comparison function for two FmtFunc entries
422
+*/
423
+static int fmtfunc_cmp(const void *pAA, const void *pBB){
424
+ const struct FmtFunc *pA = (const struct FmtFunc*)pAA;
425
+ const struct FmtFunc *pB = (const struct FmtFunc*)pBB;
426
+ return strcmp(pA->zFName, pB->zFName);
427
+}
410428
411429
/*
412430
** Determine if the indentifier zIdent of length nIndent is a Fossil
413431
** internal interface that uses a printf-style argument. Return zero if not.
414432
** Return the index of the format string if true with the left-most
@@ -625,10 +643,12 @@
625643
** The eVerbose global variable is incremented with each "-v" argument.
626644
*/
627645
int main(int argc, char **argv){
628646
int i;
629647
int nErr = 0;
648
+ qsort(aFmtFunc, sizeof(aFmtFunc)/sizeof(aFmtFunc[0]),
649
+ sizeof(aFmtFunc[0]), fmtfunc_cmp);
630650
for(i=1; i<argc; i++){
631651
char *zFile;
632652
if( strcmp(argv[i],"-v")==0 ){
633653
eVerbose++;
634654
continue;
635655
--- src/codecheck1.c
+++ src/codecheck1.c
@@ -343,48 +343,54 @@
343 }
344
345 /*
346 ** Processing flags
347 */
348 #define FMT_SQL 0x00001 /* Generates SQL text */
349 #define FMT_HTML 0x00002 /* Generates HTML text */
350 #define FMT_URL 0x00004 /* Generates URLs */
351 #define FMT_SAFE 0x00008 /* Always safe for %s */
352
353 /*
354 ** A list of internal Fossil interfaces that take a printf-style format
355 ** string.
356 */
357 struct {
358 const char *zFName; /* Name of the function */
359 int iFmtArg; /* Index of format argument. Leftmost is 1. */
360 unsigned fmtFlags; /* Processing flags */
361 } aFmtFunc[] = {
362 { "admin_log", 1, 0 },
 
 
363 { "blob_append_sql", 2, FMT_SQL },
364 { "blob_appendf", 2, 0 },
365 { "cgi_debug", 1, FMT_SAFE },
366 { "cgi_panic", 1, FMT_SAFE },
367 { "cgi_printf", 1, FMT_HTML },
 
368 { "cgi_redirectf", 1, FMT_URL },
369 { "chref", 2, FMT_URL },
 
370 { "db_blob", 2, FMT_SQL },
371 { "db_debug", 1, FMT_SQL },
372 { "db_double", 2, FMT_SQL },
373 { "db_err", 1, 0 },
374 { "db_exists", 1, FMT_SQL },
375 { "db_get_mprintf", 2, 0 },
376 { "db_int", 2, FMT_SQL },
377 { "db_int64", 2, FMT_SQL },
378 { "db_multi_exec", 1, FMT_SQL },
379 { "db_optional_sql", 2, FMT_SQL },
380 { "db_prepare", 2, FMT_SQL },
381 { "db_prepare_ignore_error", 2, FMT_SQL },
382 { "db_set_mprintf", 3, 0 },
383 { "db_static_prepare", 2, FMT_SQL },
384 { "db_text", 2, FMT_SQL },
385 { "db_unset_mprintf", 2, 0 },
 
 
386 { "form_begin", 2, FMT_URL },
387 { "fossil_error", 2, FMT_SAFE },
388 { "fossil_errorlog", 1, FMT_SAFE },
389 { "fossil_fatal", 1, FMT_SAFE },
390 { "fossil_fatal_recursive", 1, FMT_SAFE },
@@ -391,24 +397,36 @@
391 { "fossil_panic", 1, FMT_SAFE },
392 { "fossil_print", 1, FMT_SAFE },
393 { "fossil_trace", 1, FMT_SAFE },
394 { "fossil_warning", 1, FMT_SAFE },
395 { "href", 1, FMT_URL },
396 { "json_new_string_f", 1, 0 },
397 { "json_set_err", 2, 0 },
398 { "json_warn", 2, 0 },
399 { "mprintf", 1, 0 },
400 { "socket_set_errmsg", 1, 0 },
401 { "ssl_set_errmsg", 1, 0 },
 
 
 
402 { "style_header", 1, FMT_HTML },
403 { "style_js_onload", 1, FMT_HTML },
404 { "style_set_current_page", 1, FMT_URL },
405 { "style_submenu_element", 2, FMT_URL },
406 { "style_submenu_sql", 3, FMT_SQL },
407 { "webpage_error", 1, FMT_SAFE },
408 { "xhref", 2, FMT_URL },
409 };
 
 
 
 
 
 
 
 
 
410
411 /*
412 ** Determine if the indentifier zIdent of length nIndent is a Fossil
413 ** internal interface that uses a printf-style argument. Return zero if not.
414 ** Return the index of the format string if true with the left-most
@@ -625,10 +643,12 @@
625 ** The eVerbose global variable is incremented with each "-v" argument.
626 */
627 int main(int argc, char **argv){
628 int i;
629 int nErr = 0;
 
 
630 for(i=1; i<argc; i++){
631 char *zFile;
632 if( strcmp(argv[i],"-v")==0 ){
633 eVerbose++;
634 continue;
635
--- src/codecheck1.c
+++ src/codecheck1.c
@@ -343,48 +343,54 @@
343 }
344
345 /*
346 ** Processing flags
347 */
348 #define FMT_SQL 0x00001 /* Generator for SQL text */
349 #define FMT_HTML 0x00002 /* Generator for HTML text */
350 #define FMT_URL 0x00004 /* Generator for URLs */
351 #define FMT_SAFE 0x00008 /* Generator for human-readable text */
352
353 /*
354 ** A list of internal Fossil interfaces that take a printf-style format
355 ** string.
356 */
357 struct FmtFunc {
358 const char *zFName; /* Name of the function */
359 int iFmtArg; /* Index of format argument. Leftmost is 1. */
360 unsigned fmtFlags; /* Processing flags */
361 } aFmtFunc[] = {
362 { "admin_log", 1, FMT_SAFE },
363 { "audit_append", 3, FMT_SAFE },
364 { "backofficeTrace", 1, FMT_SAFE },
365 { "blob_append_sql", 2, FMT_SQL },
366 { "blob_appendf", 2, FMT_SAFE },
367 { "cgi_debug", 1, FMT_SAFE },
368 { "cgi_panic", 1, FMT_SAFE },
369 { "cgi_printf", 1, FMT_HTML },
370 { "cgi_printf_header", 1, FMT_HTML },
371 { "cgi_redirectf", 1, FMT_URL },
372 { "chref", 2, FMT_URL },
373 { "CX", 1, FMT_HTML },
374 { "db_blob", 2, FMT_SQL },
375 { "db_debug", 1, FMT_SQL },
376 { "db_double", 2, FMT_SQL },
377 { "db_err", 1, FMT_SAFE },
378 { "db_exists", 1, FMT_SQL },
379 { "db_get_mprintf", 2, FMT_SAFE },
380 { "db_int", 2, FMT_SQL },
381 { "db_int64", 2, FMT_SQL },
382 { "db_multi_exec", 1, FMT_SQL },
383 { "db_optional_sql", 2, FMT_SQL },
384 { "db_prepare", 2, FMT_SQL },
385 { "db_prepare_ignore_error", 2, FMT_SQL },
386 { "db_set_mprintf", 3, FMT_SAFE },
387 { "db_static_prepare", 2, FMT_SQL },
388 { "db_text", 2, FMT_SQL },
389 { "db_unset_mprintf", 2, FMT_SAFE },
390 { "emailerError", 2, FMT_SAFE },
391 { "fileedit_ajax_error", 2, FMT_SAFE },
392 { "form_begin", 2, FMT_URL },
393 { "fossil_error", 2, FMT_SAFE },
394 { "fossil_errorlog", 1, FMT_SAFE },
395 { "fossil_fatal", 1, FMT_SAFE },
396 { "fossil_fatal_recursive", 1, FMT_SAFE },
@@ -391,24 +397,36 @@
397 { "fossil_panic", 1, FMT_SAFE },
398 { "fossil_print", 1, FMT_SAFE },
399 { "fossil_trace", 1, FMT_SAFE },
400 { "fossil_warning", 1, FMT_SAFE },
401 { "href", 1, FMT_URL },
402 { "json_new_string_f", 1, FMT_SAFE },
403 { "json_set_err", 2, FMT_SAFE },
404 { "json_warn", 2, FMT_SAFE },
405 { "mprintf", 1, FMT_SAFE },
406 { "pop3_print", 2, FMT_SAFE },
407 { "smtp_send_line", 2, FMT_SAFE },
408 { "smtp_server_send", 2, FMT_SAFE },
409 { "socket_set_errmsg", 1, FMT_SAFE },
410 { "ssl_set_errmsg", 1, FMT_SAFE },
411 { "style_header", 1, FMT_HTML },
412 { "style_js_onload", 1, FMT_HTML },
413 { "style_set_current_page", 1, FMT_URL },
414 { "style_submenu_element", 2, FMT_URL },
415 { "style_submenu_sql", 3, FMT_SQL },
416 { "webpage_error", 1, FMT_SAFE },
417 { "xhref", 2, FMT_URL },
418 };
419
420 /*
421 ** Comparison function for two FmtFunc entries
422 */
423 static int fmtfunc_cmp(const void *pAA, const void *pBB){
424 const struct FmtFunc *pA = (const struct FmtFunc*)pAA;
425 const struct FmtFunc *pB = (const struct FmtFunc*)pBB;
426 return strcmp(pA->zFName, pB->zFName);
427 }
428
429 /*
430 ** Determine if the indentifier zIdent of length nIndent is a Fossil
431 ** internal interface that uses a printf-style argument. Return zero if not.
432 ** Return the index of the format string if true with the left-most
@@ -625,10 +643,12 @@
643 ** The eVerbose global variable is incremented with each "-v" argument.
644 */
645 int main(int argc, char **argv){
646 int i;
647 int nErr = 0;
648 qsort(aFmtFunc, sizeof(aFmtFunc)/sizeof(aFmtFunc[0]),
649 sizeof(aFmtFunc[0]), fmtfunc_cmp);
650 for(i=1; i<argc; i++){
651 char *zFile;
652 if( strcmp(argv[i],"-v")==0 ){
653 eVerbose++;
654 continue;
655
+1 -1
--- src/fileedit.c
+++ src/fileedit.c
@@ -987,11 +987,11 @@
987987
output_text_with_line_numbers(zContent, "on");
988988
}else if(zExt && zExt[1]){
989989
CX("<pre><code class='language-%s'>%h</code></pre>",
990990
zExt+1, zContent);
991991
}else{
992
- CX("<pre>%h</pre>", zExt+1, zContent);
992
+ CX("<pre>%h</pre>", zContent);
993993
}
994994
break;
995995
}
996996
}
997997
}
998998
--- src/fileedit.c
+++ src/fileedit.c
@@ -987,11 +987,11 @@
987 output_text_with_line_numbers(zContent, "on");
988 }else if(zExt && zExt[1]){
989 CX("<pre><code class='language-%s'>%h</code></pre>",
990 zExt+1, zContent);
991 }else{
992 CX("<pre>%h</pre>", zExt+1, zContent);
993 }
994 break;
995 }
996 }
997 }
998
--- src/fileedit.c
+++ src/fileedit.c
@@ -987,11 +987,11 @@
987 output_text_with_line_numbers(zContent, "on");
988 }else if(zExt && zExt[1]){
989 CX("<pre><code class='language-%s'>%h</code></pre>",
990 zExt+1, zContent);
991 }else{
992 CX("<pre>%h</pre>", zContent);
993 }
994 break;
995 }
996 }
997 }
998
+1 -1
--- src/smtp.c
+++ src/smtp.c
@@ -1528,11 +1528,11 @@
15281528
"TOP", "USER", "UIDL",
15291529
};
15301530
int i;
15311531
pop3_print(pLog, "+OK");
15321532
for(i=0; i<sizeof(azCap)/sizeof(azCap[0]); i++){
1533
- pop3_print(pLog, azCap[i]);
1533
+ pop3_print(pLog, "%s", azCap[i]);
15341534
}
15351535
pop3_print(pLog, ".");
15361536
continue;
15371537
}
15381538
if( inAuth ){
15391539
--- src/smtp.c
+++ src/smtp.c
@@ -1528,11 +1528,11 @@
1528 "TOP", "USER", "UIDL",
1529 };
1530 int i;
1531 pop3_print(pLog, "+OK");
1532 for(i=0; i<sizeof(azCap)/sizeof(azCap[0]); i++){
1533 pop3_print(pLog, azCap[i]);
1534 }
1535 pop3_print(pLog, ".");
1536 continue;
1537 }
1538 if( inAuth ){
1539
--- src/smtp.c
+++ src/smtp.c
@@ -1528,11 +1528,11 @@
1528 "TOP", "USER", "UIDL",
1529 };
1530 int i;
1531 pop3_print(pLog, "+OK");
1532 for(i=0; i<sizeof(azCap)/sizeof(azCap[0]); i++){
1533 pop3_print(pLog, "%s", azCap[i]);
1534 }
1535 pop3_print(pLog, ".");
1536 continue;
1537 }
1538 if( inAuth ){
1539

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button