Skip to content

[C++][Gandiva] gdv_hash_using_openssl() has some problems #49752

Description

@kou

Describe the bug, including details regarding any error messages, version, and platform.

See also: https://huntr.com/bounties/7a205f3c-20b3-485d-9d0a-bbcfe0d5d331

1: gdv_hash_using_openssl() is an internal function but it's exported:

GANDIVA_EXPORT
constchar* gdv_hash_using_openssl(int64_t context, constvoid* message,
size_t message_length, constEVP_MD* hash_type,
uint32_t result_buf_size, int32_t* out_length) {

2: If one of invalid digest size check and result buffer size check returns false, gdv_hash_using_openssl() should report an error. But gdv_hash_using_openssl() reports an error only when both of them return false:

if (result_length != hash_digest_size && result_buf_size != (2 * hash_digest_size)) {
gdv_fn_context_set_error_msg(context,
"Could not obtain the hash for the defined value");
EVP_MD_CTX_free(md_ctx);
OPENSSL_free(result);
*out_length = 0;
return"";
}

3: Buffer size specified to snprintf() is wrong. result_buf_size should be result_buf_size - result_buff_index.

unsignedint result_buff_index = 0;
for (unsignedint j = 0; j < result_length; j++) {
DCHECK(result_buff_index >= 0 && result_buff_index < result_buf_size);
unsignedchar hex_number = result[j];
result_buff_index +=
snprintf(result_buffer + result_buff_index, result_buf_size, "%02x", hex_number);
}

Component(s)

C++, Gandiva

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions