Skip to content

schannel: fix error check logic in get_client_cert() file reader - #22415

Closed
vszakats wants to merge 1 commit into
curl:masterfrom
vszakats:schan-minor-fail
Closed

schannel: fix error check logic in get_client_cert() file reader#22415
vszakats wants to merge 1 commit into
curl:masterfrom
vszakats:schan-minor-fail

Conversation

@vszakats

@vszakats vszakats commented Jul 28, 2026

Copy link
Copy Markdown
Member

Reported by GitHub Code Quality
Follow-up to 0fdf965 #5193


https://github.com/curl/curl/pull/22415/files?w=1

"ftell returns -1L on error, but cert_tell is declared as long
and initialized to 0. If fseek fails, continue_reading is set to
FALSE but cert_tell remains 0, and on the next line cert_tell < 0 would be false. More importantly, if continue_reading is false
after fseek, ftell is not called, but the check if(cert_tell < 0)
will still be evaluated. The check should be guarded: it should only be
reached if continue_reading is still true, otherwise the certsize
assignment on line 450 is skipped correctly but the negative check is
misleadingly evaluated. Consider restructuring so ftell is only
checked when continue_reading is true before calling it."

"`ftell` returns `-1L` on error, but `cert_tell` is declared as `long`
and initialized to `0`. If `fseek` fails, `continue_reading` is set to
`FALSE` but `cert_tell` remains `0`, and on the next line `cert_tell <
0` would be false. More importantly, if `continue_reading` is false
after `fseek`, `ftell` is not called, but the check `if(cert_tell < 0)`
will still be evaluated. The check should be guarded: it should only be
reached if `continue_reading` is still true, otherwise the `certsize`
assignment on line 450 is skipped correctly but the negative check is
misleadingly evaluated. Consider restructuring so `ftell` is only
checked when `continue_reading` is true before calling it."

Reported by GitHub Code Quality
@github-actions github-actions Bot added TLS Windows Windows-specific labels Jul 28, 2026
@vszakats vszakats closed this in 1386135 Jul 28, 2026
@vszakats
vszakats deleted the schan-minor-fail branch July 28, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

TLS Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

1 participant