2011-11-17 03:58:17 +08:00
|
|
|
// RUN: %clang_cc1 -analyze -analyzer-checker=experimental.security.taint,experimental.security.ArrayBoundV2 -verify %s
|
|
|
|
|
|
|
|
int scanf(const char *restrict format, ...);
|
|
|
|
int getchar(void);
|
|
|
|
|
|
|
|
#define BUFSIZE 10
|
|
|
|
|
|
|
|
int Buffer[BUFSIZE];
|
2011-11-29 04:43:40 +08:00
|
|
|
void bufferScanfDirect(void)
|
2011-11-17 03:58:17 +08:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
scanf("%d", &n);
|
|
|
|
Buffer[n] = 1; // expected-warning {{Out of bound memory access }}
|
|
|
|
}
|
2011-11-18 07:07:28 +08:00
|
|
|
|
|
|
|
void bufferScanfArithmetic1(int x) {
|
|
|
|
int n;
|
|
|
|
scanf("%d", &n);
|
|
|
|
int m = (n - 3);
|
|
|
|
Buffer[m] = 1; // expected-warning {{Out of bound memory access }}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bufferScanfArithmetic2(int x) {
|
|
|
|
int n;
|
|
|
|
scanf("%d", &n);
|
2011-11-29 04:43:40 +08:00
|
|
|
int m = 100 / (n + 3) * x;
|
2011-11-18 07:07:28 +08:00
|
|
|
Buffer[m] = 1; // expected-warning {{Out of bound memory access }}
|
|
|
|
}
|
2011-11-18 10:26:36 +08:00
|
|
|
|
2011-11-29 04:43:40 +08:00
|
|
|
void bufferScanfAssignment(int x) {
|
|
|
|
int n;
|
|
|
|
scanf("%d", &n);
|
|
|
|
int m;
|
|
|
|
if (x > 0) {
|
|
|
|
m = n;
|
|
|
|
Buffer[m] = 1; // expected-warning {{Out of bound memory access }}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:26:36 +08:00
|
|
|
void scanfArg() {
|
|
|
|
int t;
|
2011-12-12 02:43:40 +08:00
|
|
|
scanf("%d", t); // expected-warning {{conversion specifies type 'int *' but the argument has type 'int'}}
|
2011-11-18 10:26:36 +08:00
|
|
|
}
|
2011-11-29 04:43:40 +08:00
|
|
|
|
|
|
|
void bufferGetchar(int x) {
|
|
|
|
int m = getchar();
|
|
|
|
Buffer[m] = 1; //expected-warning {{Out of bound memory access }}
|
|
|
|
}
|