You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| resources_test.py:4:10:4:25 | ControlFlowNode for open() | File may not be closed if $@ raises an exception. | resources_test.py:5:5:5:33 | ControlFlowNode for Attribute() | this operation |
2
+
| resources_test.py:9:10:9:25 | ControlFlowNode for open() | File is opened but is not closed. | file://:0:0:0:0 | (none) | this operation |
3
+
| resources_test.py:108:11:108:20 | ControlFlowNode for open() | File is opened but is not closed. | file://:0:0:0:0 | (none) | this operation |
4
+
| resources_test.py:112:11:112:28 | ControlFlowNode for opener_func2() | File may not be closed if $@ raises an exception. | resources_test.py:113:5:113:22 | ControlFlowNode for Attribute() | this operation |
5
+
| resources_test.py:123:11:123:24 | ControlFlowNode for opener_func2() | File is opened but is not closed. | file://:0:0:0:0 | (none) | this operation |
6
+
| resources_test.py:129:15:129:24 | ControlFlowNode for open() | File may not be closed if $@ raises an exception. | resources_test.py:130:9:130:26 | ControlFlowNode for Attribute() | this operation |
7
+
| resources_test.py:248:11:248:25 | ControlFlowNode for open() | File is opened but is not closed. | file://:0:0:0:0 | (none) | this operation |
8
+
| resources_test.py:269:10:269:27 | ControlFlowNode for Attribute() | File may not be closed if $@ raises an exception. | resources_test.py:271:5:271:19 | ControlFlowNode for Attribute() | this operation |
9
+
| resources_test.py:285:11:285:20 | ControlFlowNode for open() | File may not be closed if $@ raises an exception. | resources_test.py:287:5:287:31 | ControlFlowNode for Attribute() | this operation |
f22=open(path, "wb") # $ MISSING:Alert # not closed on exception
238
238
try:
239
239
f22.write(b"foo")
240
240
may_raise()
@@ -245,7 +245,7 @@ def not_closed22(path):
245
245
f22.close()
246
246
247
247
defnot_closed23(path):
248
-
f23=open(path, "w") # $ notClosed
248
+
f23=open(path, "w") # $ Alert
249
249
wr=FileWrapper(f23)
250
250
251
251
defclosed24(path):
@@ -266,7 +266,7 @@ def closed26(path):
266
266
os.close(fd)
267
267
268
268
defnot_closed27(path):
269
-
fd=os.open(path, "w") # $notClosedOnException
269
+
fd=os.open(path, "w") # $Alert # not closed on exception
270
270
f27=os.fdopen(fd, "w")
271
271
f27.write("hi")
272
272
f27.close()
@@ -282,6 +282,53 @@ def closed28(path):
282
282
defclosed29(path):
283
283
# Due to an approximation in CFG reachability for performance, it is not detected that the `write` call that may raise occurs after the file has already been closed.
284
284
# We presume this case to be uncommon.
285
-
f28=open(path) # $SPURIOUS:notClosedOnException
285
+
f28=open(path) # $SPURIOUS:Alert # not closed on exception
286
286
f28.close()
287
-
f28.write("already closed")
287
+
f28.write("already closed")
288
+
289
+
# False positive in a previous implementation:
290
+
291
+
classNotWrapper:
292
+
def__init__(self, fp):
293
+
self.data=fp.read()
294
+
fp.close()
295
+
296
+
defdo_something(self):
297
+
pass
298
+
299
+
defclosed30(path):
300
+
# Combination of approximations resulted in this FP:
301
+
# - NotWrapper is treated as a wrapper class as a file handle is passed to it
302
+
# - thing.do_something() is treated as a call that can raise an exception while a file is open
303
+
# - this call is treated as occurring after the open but not as being guarded by the with statement, as it is in the same basic block
304
+
# - - this behavior has been changed fixing the FP
305
+
306
+
withopen(path) asfp: # No longer spurious alert here.
307
+
thing=NotWrapper(fp)
308
+
309
+
thing.do_something()
310
+
311
+
312
+
defclosed31(path):
313
+
withopen(path) asfp:
314
+
data=fp.readline()
315
+
data2=fp.readline()
316
+
317
+
318
+
classWrapper():
319
+
def__init__(self, f):
320
+
self.f=f
321
+
defread(self):
322
+
returnself.f.read()
323
+
def__enter__(self):
324
+
pass
325
+
def__exit__(self,exc_type, exc_value,traceback):
326
+
self.f.close()
327
+
328
+
defclosed32(path):
329
+
withopen(path, "rb") asf: # No longer spurious alert here.
330
+
wrap=Wrapper(f)
331
+
# This resulted in an FP in a previous implementation,
332
+
# due to a check that an operation is lexically contained within a `with` block (with `expr.getParent*()`)
0 commit comments