Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bfef1a2

Browse files
committed
C++: Apply the new pattern in other parts of StdString.qll where it matters.
1 parent b8e6ad8 commit bfef1a2

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private class StdStringCStr extends TaintFunction {
8282
* The `std::string` function `data`.
8383
*/
8484
private class StdStringData extends TaintFunction {
85-
StdStringData() { this.getDeclaringType() instanceof StdBasicString and this.hasName("data") }
85+
StdStringData() { this.getClassAndName("data") instanceof StdBasicString }
8686

8787
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
8888
// flow from string itself (qualifier) to return value
@@ -100,10 +100,7 @@ private class StdStringData extends TaintFunction {
100100
* The `std::string` function `push_back`.
101101
*/
102102
private class StdStringPush extends TaintFunction {
103-
StdStringPush() {
104-
this.getDeclaringType() instanceof StdBasicString and
105-
this.hasName("push_back")
106-
}
103+
StdStringPush() { this.getClassAndName("push_back") instanceof StdBasicString }
107104

108105
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
109106
// flow from parameter to qualifier
@@ -196,7 +193,7 @@ private class StdStringAppend extends TaintFunction {
196193
* The standard function `std::string.assign`.
197194
*/
198195
private class StdStringAssign extends TaintFunction {
199-
StdStringAssign() { this.getDeclaringType() instanceof StdBasicString and this.hasName("assign") }
196+
StdStringAssign() { this.getClassAndName("assign") instanceof StdBasicString }
200197

201198
/**
202199
* Gets the index of a parameter to this function that is a string (or
@@ -236,7 +233,7 @@ private class StdStringAssign extends TaintFunction {
236233
* The standard function `std::string.copy`.
237234
*/
238235
private class StdStringCopy extends TaintFunction {
239-
StdStringCopy() { this.getDeclaringType() instanceof StdBasicString and this.hasName("copy") }
236+
StdStringCopy() { this.getClassAndName("copy") instanceof StdBasicString }
240237

241238
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
242239
// copy(dest, num, pos)
@@ -249,7 +246,7 @@ private class StdStringCopy extends TaintFunction {
249246
* The standard function `std::string.substr`.
250247
*/
251248
private class StdStringSubstr extends TaintFunction {
252-
StdStringSubstr() { this.getDeclaringType() instanceof StdBasicString and this.hasName("substr") }
249+
StdStringSubstr() { this.getClassAndName("substr") instanceof StdBasicString }
253250

254251
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
255252
// substr(pos, num)
@@ -295,9 +292,7 @@ private class StdBasicIStream extends ClassTemplateInstantiation {
295292
* The `std::istream` function `operator>>` (defined as a member function).
296293
*/
297294
private class StdIStreamIn extends DataFlowFunction, TaintFunction {
298-
StdIStreamIn() {
299-
this.getDeclaringType() instanceof StdBasicIStream and this.hasName("operator>>")
300-
}
295+
StdIStreamIn() { this.getClassAndName("operator>>") instanceof StdBasicIStream }
301296

302297
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
303298
// returns reference to `*this`
@@ -390,9 +385,7 @@ private class StdIStreamRead extends DataFlowFunction, TaintFunction {
390385
* The `std::istream` function `readsome`.
391386
*/
392387
private class StdIStreamReadSome extends TaintFunction {
393-
StdIStreamReadSome() {
394-
this.getDeclaringType() instanceof StdBasicIStream and this.hasName("readsome")
395-
}
388+
StdIStreamReadSome() { this.getClassAndName("readsome") instanceof StdBasicIStream }
396389

397390
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
398391
// flow from qualifier to first parameter
@@ -405,9 +398,7 @@ private class StdIStreamReadSome extends TaintFunction {
405398
* The `std::istream` function `putback`.
406399
*/
407400
private class StdIStreamPutBack extends DataFlowFunction, TaintFunction {
408-
StdIStreamPutBack() {
409-
this.getDeclaringType() instanceof StdBasicIStream and this.hasName("putback")
410-
}
401+
StdIStreamPutBack() { this.getClassAndName("putback") instanceof StdBasicIStream }
411402

412403
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
413404
// returns reference to `*this`
@@ -440,9 +431,7 @@ private class StdIStreamPutBack extends DataFlowFunction, TaintFunction {
440431
* The `std::istream` function `getline`.
441432
*/
442433
private class StdIStreamGetLine extends DataFlowFunction, TaintFunction {
443-
StdIStreamGetLine() {
444-
this.getDeclaringType() instanceof StdBasicIStream and this.hasName("getline")
445-
}
434+
StdIStreamGetLine() { this.getClassAndName("getline") instanceof StdBasicIStream }
446435

447436
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
448437
// returns reference to `*this`
@@ -587,9 +576,7 @@ private class StdStringStreamConstructor extends Constructor, TaintFunction {
587576
* The `std::stringstream` function `str`.
588577
*/
589578
private class StdStringStreamStr extends TaintFunction {
590-
StdStringStreamStr() {
591-
this.getDeclaringType() instanceof StdBasicStringStream and this.hasName("str")
592-
}
579+
StdStringStreamStr() { this.getClassAndName("str") instanceof StdBasicStringStream }
593580

594581
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
595582
// flow from qualifier to return value (if any)
@@ -620,7 +607,7 @@ private class StdStreamFunction extends DataFlowFunction, TaintFunction {
620607
or
621608
this.getDeclaringType() instanceof StdBasicOStream and this.hasName(["seekp", "flush"])
622609
or
623-
this.getDeclaringType() instanceof StdBasicIOS and this.hasName("copyfmt")
610+
this.getClassAndName("copyfmt") instanceof StdBasicIOS
624611
}
625612

626613
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {

0 commit comments

Comments
 (0)