Skip to content

Commit 1c91d3d

Browse files
authored
Merge pull request github#5168 from MathiasVP/model-bsd-sockets-part-2
C++: Model vector versions of BSD-style reads and writes.
2 parents b5143db + 0f9b044 commit 1c91d3d

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

cpp/ql/src/semmle/code/cpp/models/implementations/Recv.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ private class Recv extends AliasFunction, ArrayFunction, SideEffectFunction,
1818
"recvfrom", // recvfrom(socket, dest, len, flags, from, fromlen)
1919
"recvmsg", // recvmsg(socket, msg, flags)
2020
"read", // read(socket, dest, len)
21-
"pread" // pread(socket, dest, len, offset)
21+
"pread", // pread(socket, dest, len, offset)
22+
"readv", // readv(socket, dest, len)
23+
"preadv", // readv(socket, dest, len, offset)
24+
"preadv2" // readv2(socket, dest, len, offset, flags)
2225
])
2326
}
2427

cpp/ql/src/semmle/code/cpp/models/implementations/Send.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ private class Send extends AliasFunction, ArrayFunction, SideEffectFunction, Rem
1616
"send", // send(socket, buf, len, flags)
1717
"sendto", // sendto(socket, buf, len, flags, to, tolen)
1818
"sendmsg", // sendmsg(socket, msg, flags)
19-
"write" // write(socket, buf, len);
19+
"write", // write(socket, buf, len)
20+
"writev", // writev(socket, buf, len)
21+
"pwritev", // pwritev(socket, buf, len, offset)
22+
"pwritev2" // pwritev2(socket, buf, len, offset, flags)
2023
])
2124
}
2225

cpp/ql/test/library-tests/dataflow/DefaultTaintTracking/annotate_sinks_only/defaulttainttracking.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,34 @@ void test_recv() {
228228
sink(*buffer); // $ ast,ir
229229
}
230230

231-
// --- send ---
231+
// --- send and related functions ---
232232

233233
int send(int, const void*, int, int);
234234

235235
void test_send(char* buffer, int length) {
236236
send(0, buffer, length, 0); // $ remote
237-
}
237+
}
238+
239+
struct iovec {
240+
void *iov_base;
241+
unsigned iov_len;
242+
};
243+
244+
int readv(int, const struct iovec*, int);
245+
int writev(int, const struct iovec*, int);
246+
247+
void sink(const iovec* iovs);
248+
void sink(iovec);
249+
250+
int test_readv_and_writev(iovec* iovs) {
251+
readv(0, iovs, 16);
252+
sink(iovs); // $ast,ir
253+
sink(iovs[0]); // $ast MISSING: ir
254+
sink(*iovs); // $ast MISSING: ir
255+
256+
char* p = (char*)iovs[1].iov_base;
257+
sink(p); // $ MISSING: ast,ir
258+
sink(*p); // $ MISSING: ast,ir
259+
260+
writev(0, iovs, 16); // $ remote
261+
}

0 commit comments

Comments
 (0)