You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang][analyzer] Improve test and documentation in cstring NotNullTerminated checker (#112019)
CStringChecker has a sub-checker alpha.unix.cstring.NotNullTerminated
which checks for invalid objects passed to string functions. The checker
and its name are not exact and more functions could be checked, this
change only adds some tests and improves documentation.
strcpy(x, (constchar*)&strcpy_fn); // expected-warning{{Argument to string copy function is the address of the function 'strcpy_fn', which is not a null-terminated string}}
362
362
}
363
363
364
+
voidstrcpy_fn_dst(constchar*x) {
365
+
strcpy((char*)&strcpy_fn, x); // expected-warning{{Argument to string copy function is the address of the function 'strcpy_fn', which is not a null-terminated string}}
strcat(x, NULL); // expected-warning{{Null pointer passed as 2nd argument to string concatenation function}}
470
474
}
471
475
472
-
voidstrcat_fn(char*x) {
473
-
strcat(x, (char*)&strcat_fn); // expected-warning{{Argument to string concatenation function is the address of the function 'strcat_fn', which is not a null-terminated string}}
476
+
voidstrcat_fn_dst(constchar*x) {
477
+
strcat((char*)&strcat_fn_dst, x); // expected-warning{{Argument to string concatenation function is the address of the function 'strcat_fn_dst', which is not a null-terminated string}}
478
+
}
479
+
480
+
voidstrcat_fn_src(char*x) {
481
+
strcat(x, (char*)&strcat_fn_src); // expected-warning{{Argument to string concatenation function is the address of the function 'strcat_fn_src', which is not a null-terminated string}}
482
+
}
483
+
484
+
voidstrcat_label_dst(constchar*x) {
485
+
label:
486
+
strcat((char*)&&label, x); // expected-warning{{Argument to string concatenation function is the address of the label 'label', which is not a null-terminated string}}
487
+
}
488
+
489
+
voidstrcat_label_src(char*x) {
490
+
label:
491
+
strcat(x, (char*)&&label); // expected-warning{{Argument to string concatenation function is the address of the label 'label', which is not a null-terminated string}}
strncpy(x, NULL, 5); // expected-warning{{Null pointer passed as 2nd argument to string copy function}}
569
587
}
570
588
571
-
voidstrncpy_fn(char*x) {
572
-
strncpy(x, (char*)&strcpy_fn, 5); // expected-warning{{Argument to string copy function is the address of the function 'strcpy_fn', which is not a null-terminated string}}
589
+
voidstrncpy_fn_src(char*x) {
590
+
strncpy(x, (char*)&strncpy_fn_src, 5); // expected-warning{{Argument to string copy function is the address of the function 'strncpy_fn_src', which is not a null-terminated string}}
591
+
}
592
+
593
+
voidstrncpy_fn_dst(constchar*x) {
594
+
strncpy((char*)&strncpy_fn_dst, x, 5); // expected-warning{{Argument to string copy function is the address of the function 'strncpy_fn_dst', which is not a null-terminated string}}
strncat(x, NULL, 4); // expected-warning{{Null pointer passed as 2nd argument to string concatenation function}}
681
703
}
682
704
683
-
voidstrncat_fn(char*x) {
684
-
strncat(x, (char*)&strncat_fn, 4); // expected-warning{{Argument to string concatenation function is the address of the function 'strncat_fn', which is not a null-terminated string}}
705
+
voidstrncat_fn_src(char*x) {
706
+
strncat(x, (char*)&strncat_fn_src, 4); // expected-warning{{Argument to string concatenation function is the address of the function 'strncat_fn_src', which is not a null-terminated string}}
707
+
}
708
+
709
+
voidstrncat_fn_dst(constchar*x) {
710
+
strncat((char*)&strncat_fn_dst, x, 4); // expected-warning{{Argument to string concatenation function is the address of the function 'strncat_fn_dst', which is not a null-terminated string}}
685
711
}
686
712
687
713
voidstrncat_effects(char*y) {
@@ -921,6 +947,14 @@ int strcmp_null_argument(char *a) {
921
947
returnstrcmp(a, b); // expected-warning{{Null pointer passed as 2nd argument to string comparison function}}
922
948
}
923
949
950
+
voidstrcmp_fn_r(char*x) {
951
+
strcmp(x, (char*)&strcmp_null_argument); // expected-warning{{Argument to string comparison function is the address of the function 'strcmp_null_argument', which is not a null-terminated string}}
952
+
}
953
+
954
+
voidstrcmp_fn_l(char*x) {
955
+
strcmp((char*)&strcmp_null_argument, x); // expected-warning{{Argument to string comparison function is the address of the function 'strcmp_null_argument', which is not a null-terminated string}}
0 commit comments