Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal_headers/certifier/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/certifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down