> Synopsis: Failure to detect rewind(3) errors in certificate validation
> Category: bin
> Description:
In iked(8), the ca_validate_pubkey() function uses rewind(3) to retry
reading
a public key file in a different format after the first attempt fails.
However,
rewind(3) error conditions are not checked before proceeding with the
second
read attempt.
This could lead to reading from an incorrect file position if the
stream becomes
unseekable, potentially affecting certificate validation results. The
man page
explicitly warns against using rewind(3) over fseek(3) since it hides
errors.
> Fix:
Replace:
rewind(fp);
With:
if (fseek(fp, 0L, SEEK_SET) != 0) {
log_warn("%s: could not reposition file %s", __func__, file);
fclose(fp);
goto done; // Not sslerr since this isn't an SSL error
}
This change uses the recommended fseek(3) with proper error checking and
maintains the existing error handling path through sslerr for crypto
operation failures.