diff --git a/internal_headers/certifier/error.h b/internal_headers/certifier/error.h index c4f1ff7..588abf5 100644 --- a/internal_headers/certifier/error.h +++ b/internal_headers/certifier/error.h @@ -38,6 +38,9 @@ typedef struct char * library_error_msg; } CertifierError; +/* NOTE: After assign_last_error(certifier, &tmp_err), do not call error_clear(&tmp_err) for the message pointers (they no longer belong to tmp_err). + * It’s safe to reuse tmp_err for codes, but not to free its message fields because they were moved. + */ void error_clear(CertifierError * error); enum diff --git a/src/certifier.c b/src/certifier.c index 93b0f3f..d60c1e5 100644 --- a/src/certifier.c +++ b/src/certifier.c @@ -845,7 +845,15 @@ void certifier_print_certificate_validity(Certifier * certifier) static inline void assign_last_error(Certifier * certifier, CertifierError * error) { error_clear(&certifier->last_error); - certifier->last_error = *error; + certifier->last_error.application_error_code = error->application_error_code; + certifier->last_error.library_error_code = error->library_error_code; + certifier->last_error.application_error_msg = error->application_error_msg; + certifier->last_error.library_error_msg = error->library_error_msg; + // Prevent double-free by nulling source pointers + error->application_error_msg = NULL; + error->library_error_msg = NULL; + error->application_error_code = 0; + error->library_error_code = 0; } /**