Skip to content

Commit 8243bc4

Browse files
committed
[analyzer] Make socket accept() propagate taint (#66074)
This allows to track taint on real code from `socket()` to reading into a buffer using `recv()`. #66074
1 parent 909c963 commit 8243bc4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ void GenericTaintChecker::initTaintRules(CheckerContext &C) const {
621621
{{{"getlogin_r"}}, TR::Source({{0}})},
622622

623623
// Props
624+
{{{"accept"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
624625
{{{"atoi"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
625626
{{{"atol"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},
626627
{{{"atoll"}}, TR::Prop({{0}}, {{ReturnValueIndex}})},

clang/test/Analysis/taint-generic.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,10 @@ void testFread(const char *fname, int *buffer, size_t size, size_t count) {
544544
}
545545

546546
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
547+
int accept(int fd, struct sockaddr *addr, socklen_t *addrlen);
548+
int bind(int fd, const struct sockaddr *addr, socklen_t addrlen);
549+
int listen(int fd, int backlog);
550+
547551
void testRecv(int *buf, size_t len, int flags) {
548552
int fd;
549553
scanf("%d", &fd); // fake a tainted a file descriptor
@@ -1107,3 +1111,10 @@ void testProctitle2(char *real_argv[]) {
11071111
setproctitle_init(1, argv, 0); // expected-warning {{Untrusted data is passed to a user-defined sink}}
11081112
setproctitle_init(1, real_argv, argv); // expected-warning {{Untrusted data is passed to a user-defined sink}}
11091113
}
1114+
1115+
void testAcceptPropagates() {
1116+
int listenSocket = socket(2, 1, 6);
1117+
clang_analyzer_isTainted_int(listenSocket); // expected-warning {{YES}}
1118+
int acceptSocket = accept(listenSocket, 0, 0);
1119+
clang_analyzer_isTainted_int(acceptSocket); // expected-warning {{YES}}
1120+
}

0 commit comments

Comments
 (0)