Skip to content

Commit

Permalink
MONGOCRYPT-519 wrap errors from processing crypt_shared markings (#538)
Browse files Browse the repository at this point in the history
* wrap errors from processing crypt_shared markings

* note safety of wrapping errors
  • Loading branch information
kevinAlbs authored Jan 20, 2023
1 parent 2c2d78e commit 4a4cd1c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/mongocrypt-ctx-encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,15 +1075,25 @@ _try_run_csfle_marking (mongocrypt_ctx_t *ctx)
mongocrypt_binary_t *marked =
mongocrypt_binary_new_from_data (marked_bson, marked_bson_len);
if (!_mongo_feed_markings (ctx, marked)) {
_mongocrypt_ctx_fail_w_msg (
ctx, "Consuming the generated csfle markings failed");
// Wrap error with additional information.
_mongocrypt_set_error (
ctx->status,
MONGOCRYPT_STATUS_ERROR_CLIENT,
MONGOCRYPT_GENERIC_ERROR_CODE,
"Consuming the generated csfle markings failed: %s",
mongocrypt_status_message (ctx->status, NULL /* len */));
goto fail_feed_markings;
}

okay = _mongo_done_markings (ctx);
if (!okay) {
_mongocrypt_ctx_fail_w_msg (
ctx, "Finalizing the generated csfle markings failed");
// Wrap error with additional information.
_mongocrypt_set_error (
ctx->status,
MONGOCRYPT_STATUS_ERROR_CLIENT,
MONGOCRYPT_GENERIC_ERROR_CODE,
"Finalizing the generated csfle markings failed: %s",
mongocrypt_status_message (ctx->status, NULL /* len */));
}

fail_feed_markings:
Expand Down
10 changes: 9 additions & 1 deletion src/mongocrypt-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ tmp_json (const bson_t *bson);
const char *
tmp_buf (const _mongocrypt_buffer_t *buf);


// _mongocrypt_set_error sets an error status.
// `status->message` is set after evaluating `format` and variadic args.
// It is safe to uses a `status->message` as an argument to wrap an error. For example:
// _mongocrypt_set_error (
// status,
// MONGOCRYPT_STATUS_ERROR_CLIENT,
// MONGOCRYPT_GENERIC_ERROR_CODE,
// "Error occurred. Original error: %s",
// mongocrypt_status_message (status, NULL /* len */));
MLIB_ANNOTATE_PRINTF (4, 5)
void
_mongocrypt_set_error (mongocrypt_status_t *status,
Expand Down

0 comments on commit 4a4cd1c

Please sign in to comment.