llvm-project/clang/test/Analysis/taint-checker-callback-order-without-definition.c
Balazs Benics 7036413dc2 Revert "Revert "[analyzer] Fix taint rule of fgets and setproctitle_init""
This reverts commit 2acead35c1289d2b3593a992b0639ca6427e481f.

Let's try `REQUIRES: asserts`.
2022-02-23 12:55:31 +01:00

32 lines
1.1 KiB
C

// RUN: %clang_analyze_cc1 %s \
// RUN: -analyzer-checker=core,alpha.security.taint \
// RUN: -mllvm -debug-only=taint-checker \
// RUN: 2>&1 | FileCheck %s
// REQUIRES: asserts
struct _IO_FILE;
typedef struct _IO_FILE FILE;
FILE *fopen(const char *fname, const char *mode);
char *fgets(char *s, int n, FILE *fp); // no-definition
void top(const char *fname, char *buf) {
FILE *fp = fopen(fname, "r"); // Introduce taint.
// CHECK: PreCall<fopen(fname, "r")> prepares tainting arg index: -1
// CHECK-NEXT: PostCall<fopen(fname, "r")> actually wants to taint arg index: -1
if (!fp)
return;
(void)fgets(buf, 42, fp); // Trigger taint propagation.
// CHECK-NEXT: PreCall<fgets(buf, 42, fp)> prepares tainting arg index: -1
// CHECK-NEXT: PreCall<fgets(buf, 42, fp)> prepares tainting arg index: 0
// CHECK-NEXT: PreCall<fgets(buf, 42, fp)> prepares tainting arg index: 2
//
// CHECK-NEXT: PostCall<fgets(buf, 42, fp)> actually wants to taint arg index: -1
// CHECK-NEXT: PostCall<fgets(buf, 42, fp)> actually wants to taint arg index: 0
// CHECK-NEXT: PostCall<fgets(buf, 42, fp)> actually wants to taint arg index: 2
}