Skip to content

Fix CodeQL warning-severity alerts: process stream ownership and two leaks - #799

Merged
vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:codeql-warning-resource-leaks
Jul 31, 2026
Merged

vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:codeql-warning-resource-leaks

Conversation

@vharseko

Copy link
Copy Markdown
Member

Closes the remaining nine warning-severity Code Scanning alerts on master (there are no error-severity ones left).

Process stream readers — alerts #713–#718 (java/input-resource-leak)

OutputReader, StopReader and StartReader already closed the reader handed to them, but they did so on their own background thread, which java/input-resource-leak cannot follow. The readers now take the raw InputStream and build the InputStreamReader/BufferedReader inside the try-with-resources of the consuming thread, so a single owner creates and closes the whole chain.

While there, InstallerHelper.invokeImportLDIF() no longer closes process.getErrorStream() in its finally block — that stream belongs to the reader started just above, and closing it from another thread could cut the tail of the error log short. What is left to close is process.getOutputStream(), which is the standard input of the process and was mislabelled as its output.

ID2Entry — alert #1237 (java/input-resource-leak)

The stream chain was assembled through repeated assignments to one variable before being handed to try-with-resources, which the query loses track of. It is now built by newEntryInputStream() and passed straight into the resource specification. This also closes the theoretical window where the cipher stream would be left open if the InflaterInputStream constructor failed.

Utils.copyFile — alert #708 (java/input-resource-leak)

The only genuine leak of the batch: copyInputStreamToFile() closes its argument in a finally block that starts after createFile(copy), so a failure there left the FileInputStream opened by copyFile() behind. copyFile() now owns its stream through try-with-resources, and createFile() moved inside the guarded region.

ImportTask.initializeTask — alert #769 (java/dereferenced-value-may-be-null)

Not reachable in practice: a null backend ID implies at least one include branch, and every include branch either resolves to a backend or is rejected. The guard mirrors the one runTask() already has, documents why the path is dead and keeps the dereference below safe.

Testing

  • mvn compile on opendj-doc-maven-plugin and opendj-server-legacy
  • full opendj-server-legacy packaging (jars, assemblies, server archive)
  • mvn verify -Pprecommit -pl opendj-server-legacy -Dit.test=JETestCase — 33 tests, 0 failures; covers the ID2Entry entry decoding path

…leaks

Move the wrapping of process streams into the consuming thread of OutputReader,
StopReader and StartReader, so that each reader is the sole owner of the whole
chain and java/input-resource-leak no longer loses track of it across the thread
handoff. InstallerHelper no longer closes the error stream owned by its reader,
and closes the standard input of the process instead of mislabelling it as its
output.

Build the entry input stream chain of ID2Entry in a dedicated method so that it
is passed directly to try-with-resources, and close the input stream of
Utils.copyFile even when creating the destination file fails.

Guard against a null backend in ImportTask.initializeTask() the way runTask()
already does.
@vharseko
vharseko requested a review from maximthomas July 31, 2026 08:54
@vharseko vharseko added security Security fixes / CodeQL code-scanning alerts java labels Jul 31, 2026
@vharseko
vharseko merged commit 44b37af into OpenIdentityPlatform:master Jul 31, 2026
17 checks passed
@vharseko
vharseko deleted the codeql-warning-resource-leaks branch July 31, 2026 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security Security fixes / CodeQL code-scanning alerts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants