False Negative: CloseWriter.ql misses leaked wrapped streams when the close is skipped by an early return or hidden in a factory.
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 52/100
Línea de trabajo
Empieza leyendo Likely Bugs/Resource Leaks/CloseWriter.ql e inspecciona los casos afectados en PosCase2_Var3.java y PosCase2_Var5.java. Sigue cómo la consulta gestiona los retornos anticipados y los streams creados por helpers, y luego ejecuta las pruebas relevantes de CloseWriter. Se considera terminado cuando ambos casos se reporten como leaks sin romper la cobertura existente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Version
codeql 2.24.3
Checker
- Checker id:
Likely Bugs/Resource Leaks/CloseWriter.ql - Checker description: This checker detects instances where a Writer or OutputStream is created but not guaranteed to be closed on method exit, potentially causing resource leaks.
Description of the false negative
Both examples still leak the underlying file stream. One exits the method before the wrapper is closed. The other moves stream construction into a helper and then never closes the returned wrapper.
Those are ordinary resource-leak scenarios. Neither refactoring changes the ownership or lifetime of the stream.
Affected test cases
PosCase2_Var3.java
The return bypasses the only close() call. bos and the wrapped FileOutputStream both remain unclosed on the live path.
// FileOutputStream passed to BufferedOutputStream where inner resource not guaranteed to be closed should be flagged.
package scensct.var.pos;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class PosCase2_Var3 {
public void writeBuffered() throws IOException {
// Variant 3: Introduce early return that skips close
FileOutputStream fos = new FileOutputStream("data.bin");
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(1);
if (System.currentTimeMillis() > 0) {
return; // exit without closing
}
// Unreachable code, close never called
bos.close();
}
}
PosCase2_Var5.java
The factory method only hides allocation. It does not transfer cleanup responsibility anywhere else, and the caller still never closes the returned stream.
// FileOutputStream passed to BufferedOutputStream where inner resource not guaranteed to be closed should be flagged.
package scensct.var.pos;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class PosCase2_Var5 {
public void writeBuffered() throws IOException {
// Variant 5: Wrap in a method that returns the BufferedOutputStream without closing
BufferedOutputStream bos = openBufferedStream("data.bin");
bos.write(1);
// Not closed
}
private BufferedOutputStream openBufferedStream(String file) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
return new BufferedOutputStream(fos);
}
}
Cause analysis
Likely Bugs/Resource Leaks/CloseWriter.ql looks too dependent on one direct construction-and-close pattern. As soon as the leak is expressed through an early return or a helper that returns the wrapper, the result disappears.
That is too brittle for a resource-leak query. In real code, stream creation is often factored into small helpers, and missing close calls frequently happen on short-circuit exits.
- Lenguaje dominante
- CodeQL
- Estrellas
- 10.1k
- Forks
- 2.1k
- Merge medio
- 2 d 16 h
- PR fusionados (30 d)
- 143
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de github/codeql
-
agentic-workflows
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
false-positive javascript
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
-
C#: cs/simplifiable-boolean-expression false positive on Nullable<bool> compared with a literal Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
false-positive
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Todos los issues de github/codeql
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
punkpeye/mcp-remote#369 ·
-
Mend: dependency security vulnerability untriaged
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
CVE-2024-24786 CPE mismatch Abiertobug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
cisagov/vulnrichment#337 ·
-
bug DUP Reservations
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
bcgov/reserve-rec-public#896 ·