Skip to content

fix(import): read the csv fd before fclose - #73

Merged
mscasso-scanoss merged 1 commit into
crc64from
fix/import-fileno-after-fclose
Oct 28, 2026
Merged

mscasso-scanoss merged 1 commit into
crc64from
fix/import-fileno-after-fclose

Conversation

@mscasso-scanoss

Copy link
Copy Markdown
Collaborator

Why

ldb_import_csv reports a failed fclose(fp) with fileno(fp), called after the stream was closed. That reads a freed FILE (use-after-free); gcc flags it on every build:

src/import.c:927:17: warning: pointer 'fp' may be used after 'fclose' [-Wuse-after-free]

It only runs on the error path of fclose, so it has not caused visible problems, but the printed fd is undefined and the access is invalid.

Change

Take the fd before closing, the same pattern master already uses in src/import.c. No behavior change otherwise.

Testing

  • src/import.c compiles with the Makefile flags (-O -Wall ...) with no warnings.
  • No other fileno call after fclose in src/.

🤖 Generated with Claude Code

ldb_import_csv called fileno(fp) after fclose(fp) to report a close error,
which is a use-after-free (gcc -Wuse-after-free). Take the fd first, as
master already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mscasso-scanoss mscasso-scanoss self-assigned this Oct 28, 2026
@mscasso-scanoss
mscasso-scanoss merged commit 1bdee81 into crc64 Oct 28, 2026
1 check passed
@mscasso-scanoss
mscasso-scanoss deleted the fix/import-fileno-after-fclose branch October 28, 2026 16:50
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