56
56
// CHECK-INVALID-ARG-SAME: rules greater or equal to -1
57
57
58
58
typedef long long rsize_t ;
59
+ typedef typeof (sizeof (int )) size_t ;
60
+ typedef __WCHAR_TYPE__ wchar_t ;
59
61
void clang_analyzer_isTainted_char (char );
62
+ void clang_analyzer_isTainted_wchar (wchar_t );
60
63
void clang_analyzer_isTainted_charp (char * );
61
64
void clang_analyzer_isTainted_int (int );
62
65
@@ -75,6 +78,17 @@ extern FILE *stdin;
75
78
#define bool _Bool
76
79
#define NULL (void*)0
77
80
81
+ wchar_t * fgetws (wchar_t * ws , int n , FILE * stream );
82
+ wchar_t * wmemset (wchar_t * wcs , wchar_t wc , unsigned long n );
83
+ wchar_t * wmemcpy (wchar_t * dest , const wchar_t * src , size_t n );
84
+ wchar_t * wmemmove (wchar_t * dest , const wchar_t * src , size_t n );
85
+ size_t wcslen (const wchar_t * s );
86
+ wchar_t * wcscpy (wchar_t * dest , const wchar_t * src );
87
+ wchar_t * wcsncpy (wchar_t * dest , const wchar_t * src , size_t n );
88
+ wchar_t * wcscat (wchar_t * dest , const wchar_t * src );
89
+ wchar_t * wcsncat (wchar_t * dest ,const wchar_t * src , size_t n );
90
+ int swprintf (wchar_t * wcs , size_t maxlen , const wchar_t * format , ...);
91
+
78
92
char * getenv (const char * name );
79
93
80
94
FILE * fopen (const char * name , const char * mode );
@@ -430,6 +444,24 @@ int testSprintf_propagates_taint(char *buf, char *msg) {
430
444
return 1 / x ; // expected-warning {{Division by a tainted value, possibly zero}}
431
445
}
432
446
447
+ void test_wchar_apis_propagate (const char * path ) {
448
+ FILE * f = fopen (path , "r" );
449
+ clang_analyzer_isTainted_charp ((char * )f ); // expected-warning {{YES}}
450
+ wchar_t wbuf [10 ];
451
+ fgetws (wbuf , sizeof (wbuf )/sizeof (* wbuf ), f );
452
+ clang_analyzer_isTainted_wchar (* wbuf ); // expected-warning {{YES}}
453
+ int n = wcslen (wbuf );
454
+ clang_analyzer_isTainted_int (n ); // expected-warning {{YES}}
455
+
456
+ wchar_t dst [100 ] = L"ABC" ;
457
+ clang_analyzer_isTainted_wchar (* dst ); // expected-warning {{NO}}
458
+ wcsncat (dst , wbuf , sizeof (wbuf )/sizeof (* wbuf ));
459
+ clang_analyzer_isTainted_wchar (* dst ); // expected-warning {{YES}}
460
+
461
+ int m = wcslen (dst );
462
+ clang_analyzer_isTainted_int (m ); // expected-warning {{YES}}
463
+ }
464
+
433
465
int scanf_s (const char * format , ...);
434
466
int testScanf_s_ (int * out ) {
435
467
scanf_s ("%d" , out );
@@ -644,7 +676,6 @@ void testRawmemchr(int c) {
644
676
clang_analyzer_isTainted_charp (result ); // expected-warning {{YES}}
645
677
}
646
678
647
- typedef char wchar_t ;
648
679
int mbtowc (wchar_t * pwc , const char * s , size_t n );
649
680
void testMbtowc (wchar_t * pwc , size_t n ) {
650
681
char buf [10 ];
@@ -657,8 +688,7 @@ void testMbtowc(wchar_t *pwc, size_t n) {
657
688
658
689
int wctomb (char * s , wchar_t wc );
659
690
void testWctomb (char * buf ) {
660
- wchar_t wc ;
661
- scanf ("%c" , & wc );
691
+ wchar_t wc = getchar ();
662
692
663
693
int result = wctomb (buf , wc );
664
694
clang_analyzer_isTainted_char (* buf ); // expected-warning {{YES}}
@@ -667,8 +697,7 @@ void testWctomb(char *buf) {
667
697
668
698
int wcwidth (wchar_t c );
669
699
void testWcwidth () {
670
- wchar_t wc ;
671
- scanf ("%c" , & wc );
700
+ wchar_t wc = getchar ();
672
701
673
702
int width = wcwidth (wc );
674
703
clang_analyzer_isTainted_int (width ); // expected-warning {{YES}}
0 commit comments