]> git.99rst.org Git - git.git/commit
mailsplit: move NULL check before first use of file handle
authorJohannes Schindelin <redacted>
Fri, 10 Jul 2026 11:39:29 +0000 (11:39 +0000)
committerJunio C Hamano <redacted>
Fri, 10 Jul 2026 15:13:54 +0000 (08:13 -0700)
commit775f1f2b19e1c3d133356170373fedeb363988a3
tree1f82be09c870948e0e8fd17254c96b4820bea5be
parentd321f42c09b4f01978592cb2a4b8dc5fd86a5e12
mailsplit: move NULL check before first use of file handle

The `split_mbox()` function calls fileno(f) to check whether the input
is a terminal, but the NULL check for f (from `fopen()`) does not happen
until later. When the file cannot be opened, f is NULL, and
`fileno(NULL)` is undefined behavior, typically crashing with a
segmentation fault.

Move the NULL check above the `isatty()`/`fileno()` call so the error
path is taken before any use of the potentially-NULL handle.

Pointed out by Coverity.

Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <redacted>
Signed-off-by: Junio C Hamano <redacted>
builtin/mailsplit.c
git clone https://git.99rst.org/PROJECT