Skip to content

Commit c2ef58d

Browse files
committed
C++: Support 'readlinkat'.
1 parent 358d89f commit c2ef58d

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

cpp/ql/src/Likely Bugs/Memory Management/ImproperNullTermination.ql

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ class ImproperNullTerminationReachability extends StackVariableReachabilityWithR
2929
override predicate isSourceActual(ControlFlowNode node, StackVariable v) {
3030
node = declWithNoInit(v)
3131
or
32-
exists(Call c, VariableAccess va |
32+
exists(Call c, int arg |
3333
c = node and
34-
c.getTarget().hasName("readlink") and
35-
c.getArgument(1) = va and
36-
va.getTarget() = v
34+
(
35+
c.getTarget().hasName("readlink") and arg = 1
36+
or
37+
c.getTarget().hasName("readlinkat") and arg = 2
38+
) and
39+
c.getArgument(arg).(VariableAccess).getTarget() = v
3740
)
3841
}
3942

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ImproperNullTermination/ImproperNullTermination.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
| test.cpp:116:10:116:15 | buffer | Variable $@ may not be null terminated. | test.cpp:109:8:109:13 | buffer | buffer |
1111
| test.cpp:130:14:130:19 | buffer | Variable $@ may not be null terminated. | test.cpp:127:7:127:12 | buffer | buffer |
1212
| test.cpp:139:10:139:15 | buffer | Variable $@ may not be null terminated. | test.cpp:136:8:136:13 | buffer | buffer |
13+
| test.cpp:147:14:147:19 | buffer | Variable $@ may not be null terminated. | test.cpp:143:8:143:13 | buffer | buffer |
1314
| test.cpp:154:10:154:15 | buffer | Variable $@ may not be null terminated. | test.cpp:151:8:151:13 | buffer | buffer |
1415
| test.cpp:162:10:162:15 | buffer | Variable $@ may not be null terminated. | test.cpp:158:8:158:13 | buffer | buffer |
1516
| test.cpp:170:10:170:15 | buffer | Variable $@ may not be null terminated. | test.cpp:166:8:166:13 | buffer | buffer |

cpp/ql/test/query-tests/Likely Bugs/Memory Management/ImproperNullTermination/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void test_readlink(int fd, const char *path, size_t sz)
144144
int v;
145145

146146
readlinkat(fd, path, buffer, sizeof(buffer));
147-
v = strlen(buffer); // BAD [NOT DETECTED]
147+
v = strlen(buffer); // BAD
148148
}
149149

150150
{

0 commit comments

Comments
 (0)