Skip to content

Commit e9dd4a8

Browse files
author
Nikita Kraiouchkine
committed
Update strtok param indices in OutOfBounds library
1 parent 883ecca commit e9dd4a8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

c/common/src/codingstandards/c/OutOfBounds.qll

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ module OOB {
8282
dst = -1 and
8383
src = [0, 1]
8484
or
85-
name = "strtok" and
86-
dst = 0 and
87-
src = 1
85+
// do not specify a src and dst to avoid buffer size assumptions
86+
name = ["strtok", "strtok_r"] and
87+
dst = -1 and
88+
src = [0, 1]
8889
)
8990
}
9091

@@ -479,6 +480,18 @@ module OOB {
479480
}
480481
}
481482

483+
/**
484+
* A `BufferAccessLibraryFunction` modelling `strtok`
485+
*/
486+
class StrtokLibraryFunction extends BufferAccessLibraryFunction {
487+
StrtokLibraryFunction() { this.getName() = getNameOrInternalName(["strtok", "strtok_r"]) }
488+
489+
override predicate getAPermissiblyNullParameterIndex(int i) {
490+
// `strtok` does not require a non-null `str` parameter
491+
i = 0
492+
}
493+
}
494+
482495
/**
483496
* An construction of a pointer to a buffer.
484497
*/

0 commit comments

Comments
 (0)