Error data is always a NUL-terminated malloced string.

Cut down on the number of cases we need to worry about here. In
particular, it would be useful for the handshake to be able to replay an
error.

Change-Id: I2345faaff5503ede1324a5599e680de83f4b106e
Reviewed-on: https://boringssl-review.googlesource.com/21004
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Steven Valdez <svaldez@google.com>
Reviewed-by: Steven Valdez <svaldez@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
David Benjamin 2017-09-28 16:33:09 -04:00 committed by CQ bot account: commit-bot@chromium.org
parent f496249405
commit e1c3dad959
2 changed files with 12 additions and 21 deletions

View File

@ -131,11 +131,8 @@ extern const char kOpenSSLReasonStringData[];
// err_clear_data frees the optional |data| member of the given error.
static void err_clear_data(struct err_error_st *error) {
if ((error->flags & ERR_FLAG_MALLOCED) != 0) {
OPENSSL_free(error->data);
}
OPENSSL_free(error->data);
error->data = NULL;
error->flags &= ~ERR_FLAG_MALLOCED;
}
// err_clear clears the given queued error.
@ -235,7 +232,7 @@ static uint32_t get_error_values(int inc, int top, const char **file, int *line,
// ownership and retains it until the next call that affects the
// error queue.
if (inc) {
if (error->flags & ERR_FLAG_MALLOCED) {
if (error->data != NULL) {
OPENSSL_free(state->to_free);
state->to_free = error->data;
}
@ -585,16 +582,13 @@ void ERR_print_errors_fp(FILE *file) {
ERR_print_errors_cb(print_errors_to_file, file);
}
// err_set_error_data sets the data on the most recent error. The |flags|
// argument is a combination of the |ERR_FLAG_*| values.
static void err_set_error_data(char *data, int flags) {
// err_set_error_data sets the data on the most recent error.
static void err_set_error_data(char *data) {
ERR_STATE *const state = err_get_state();
struct err_error_st *error;
if (state == NULL || state->top == state->bottom) {
if (flags & ERR_FLAG_MALLOCED) {
OPENSSL_free(data);
}
OPENSSL_free(data);
return;
}
@ -602,7 +596,7 @@ static void err_set_error_data(char *data, int flags) {
err_clear_data(error);
error->data = data;
error->flags = flags;
error->flags = ERR_FLAG_STRING;
}
void ERR_put_error(int library, int unused, int reason, const char *file,
@ -680,7 +674,7 @@ static void err_add_error_vdata(unsigned num, va_list args) {
}
buf[len] = 0;
err_set_error_data(buf, ERR_FLAG_MALLOCED | ERR_FLAG_STRING);
err_set_error_data(buf);
}
void ERR_add_error_data(unsigned count, ...) {
@ -708,7 +702,7 @@ void ERR_add_error_dataf(const char *format, ...) {
buf[buf_len] = 0;
va_end(ap);
err_set_error_data(buf, ERR_FLAG_MALLOCED | ERR_FLAG_STRING);
err_set_error_data(buf);
}
int ERR_set_mark(void) {

View File

@ -331,8 +331,8 @@ OPENSSL_EXPORT int ERR_pop_to_mark(void);
struct err_error_st {
// file contains the filename where the error occurred.
const char *file;
// data contains optional data. It must be freed with |OPENSSL_free| if
// |flags&ERR_FLAG_MALLOCED|.
// data contains a NUL-terminated string with optional data. It must be freed
// with |OPENSSL_free|.
char *data;
// packed contains the error library and reason, as packed by ERR_PACK.
uint32_t packed;
@ -343,7 +343,7 @@ struct err_error_st {
};
// ERR_FLAG_STRING means that the |data| member is a NUL-terminated string that
// can be printed.
// can be printed. This is always set if |data| is non-NULL.
#define ERR_FLAG_STRING 1
// ERR_TXT_STRING is provided for compatibility with code that assumes that
// it's using OpenSSL.
@ -356,12 +356,9 @@ struct err_error_st {
// The following flag values are internal and are masked when flags are
// returned from functions like |ERR_get_error_line_data|.
// ERR_FLAG_MALLOCED means the the |data| member must be freed when no longer
// needed.
#define ERR_FLAG_MALLOCED 16
// ERR_FLAG_MARK is used to indicate a reversion point in the queue. See
// |ERR_pop_to_mark|.
#define ERR_FLAG_MARK 32
#define ERR_FLAG_MARK 16
// ERR_NUM_ERRORS is the limit of the number of errors in the queue.
#define ERR_NUM_ERRORS 16