Skip to content

Commit ac24fdd

Browse files
committed
Add predicate to detect non-stream-like usage in sources of pipe calls
1 parent 5b1af0c commit ac24fdd

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

javascript/ql/src/Quality/UnhandledStreamPipe.ql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,28 @@ predicate hasNonNodeJsStreamSource(PipeCall pipeCall) {
207207
pipeResultRef(pipeCall) = getNonNodeJsStreamType()
208208
}
209209

210+
/**
211+
* Holds if the source stream of the given pipe call is used in a non-stream-like way.
212+
*/
213+
private predicate hasNonStreamSourceLikeUsage(PipeCall pipeCall) {
214+
exists(DataFlow::MethodCallNode call, string name |
215+
call.getReceiver().getALocalSource() = streamRef(pipeCall) and
216+
name = call.getMethodName() and
217+
not name = getStreamMethodName()
218+
)
219+
or
220+
exists(DataFlow::PropRef propRef, string propName |
221+
propRef.getBase().getALocalSource() = streamRef(pipeCall) and
222+
propName = propRef.getPropertyName() and
223+
not propName = [getStreamPropertyName(), getStreamMethodName()]
224+
)
225+
}
226+
210227
from PipeCall pipeCall
211228
where
212229
not hasErrorHandlerRegistered(pipeCall) and
213230
not isPipeFollowedByNonStreamAccess(pipeCall) and
231+
not hasNonStreamSourceLikeUsage(pipeCall) and
214232
not hasNonNodeJsStreamSource(pipeCall)
215233
select pipeCall,
216234
"Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped."

javascript/ql/test/query-tests/Quality/UnhandledStreamPipe/test.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@
1111
| test.js:143:5:143:62 | stream. ... itable) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |
1212
| test.js:175:17:175:40 | notStre ... itable) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |
1313
| test.js:185:5:185:32 | copyStr ... nation) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |
14-
| test.js:190:17:190:40 | notStre ... itable) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |
15-
| test.js:195:17:195:40 | notStre ... itable) | Stream pipe without error handling on the source stream. Errors won't propagate downstream and may be silently dropped. |

javascript/ql/test/query-tests/Quality/UnhandledStreamPipe/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ function test() {
187187
{
188188
const notStream = getNotAStream();
189189
const something = notStream.someNotStreamPropertyAccess;
190-
const val = notStream.pipe(writable); // $SPURIOUS:Alert
190+
const val = notStream.pipe(writable);
191191
}
192192
{
193193
const notStream = getNotAStream();
194194
const something = notStream.someNotStreamPropertyAccess();
195-
const val = notStream.pipe(writable); // $SPURIOUS:Alert
195+
const val = notStream.pipe(writable);
196196
}
197197
{
198198
const notStream = getNotAStream();

0 commit comments

Comments
 (0)