Skip to content

fix(codeql): check Close() on writable file handles#13

Merged
amiwrpremium merged 1 commit into
masterfrom
fix/codeql-unhandled-close
Apr 21, 2026
Merged

fix(codeql): check Close() on writable file handles#13
amiwrpremium merged 1 commit into
masterfrom
fix/codeql-unhandled-close

Conversation

@amiwrpremium
Copy link
Copy Markdown
Owner

Resolves 3 of 7 open CodeQL go/unhandled-writable-file-close alerts. Upload-target Close is a real fix; two lockfile Closes are flock-only but satisfy the linter.

CodeQL's go/unhandled-writable-file-close flagged three spots
where a writable file handle's Close() return was ignored via
`defer`. Two are instance-lock files (never written; close
genuinely can't lose data but CodeQL's flow analysis traces the
O_RDWR open and warns anyway). One is a real upload-target in
internal/files/files.go — ignoring that Close() would mask flush
or fsync errors, the only way a successful Copy → silent data
loss can happen.

- `internal/files/files.go:126` — real fix. Replace
  `defer out.Close()` with an explicit close-and-check on each
  exit path; surface close errors as a failed upload.
- `cmd/shellboto/main.go:95` — lockfile Close() wrapped in
  a defer that logs on error (via zap Warn).
- `cmd/shellboto/cmd_db.go:174` — same, logs to stderr.

Closes 3 of the 7 open CodeQL alerts. The remaining 4
(go/incorrect-integer-conversion on uid/gid → int narrowing)
are false positives on our 64-bit-only build targets; dismissed
via the security tab separately.
@amiwrpremium amiwrpremium merged commit 43c0b80 into master Apr 21, 2026
13 checks passed
@amiwrpremium amiwrpremium deleted the fix/codeql-unhandled-close branch April 21, 2026 11:49
amiwrpremium added a commit that referenced this pull request Apr 21, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.1.1](v0.1.0...v0.1.1)
(2026-04-21)


### Bug fixes

* **ci:** commit-msg regex accepts multiple parenthesised scopes
([#10](#10))
([fa8a3ff](fa8a3ff))
* **codeql:** check Close() on writable file handles
([#13](#13))
([43c0b80](43c0b80))


### CI

* **release-please:** authenticate via RELEASE_PLEASE_TOKEN PAT
([#14](#14))
([7434055](7434055))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: AMiWR <83715695+amiwrpremium@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant