Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NULL dereference on memory allocation error (src/ flb_avro) #3044

Closed
raminfp opened this issue Feb 9, 2021 · 3 comments
Closed

NULL dereference on memory allocation error (src/ flb_avro) #3044

raminfp opened this issue Feb 9, 2021 · 3 comments

Comments

@raminfp
Copy link

raminfp commented Feb 9, 2021

Bug Report

Describe the bug

NULL dereference (value returned by flb_malloc is not checked) after memory allocation error (flb_malloc is wrapper on malloc returning NULL on unsuccessful allocation).
In most cases this issue will lead to crash via segmentation fault.

Vulnerable Code

flb_sds_t flb_msgpack_raw_to_avro_sds(const void *in_buf, size_t in_size, struct flb_avro_fields *ctx)
{
    msgpack_unpacked result;
    msgpack_object *root;

    size_t avro_buffer_size = in_size * 3;
    char *out_buff = flb_malloc(avro_buffer_size);

    .... SKIP.....

   flb_debug("before avro_writer_memory\n");
    awriter = avro_writer_memory(out_buff, avro_buffer_size);
    if (awriter == NULL) {

To Reproduce
Problem was identified by source code review.

Expected behavior

Memory allocation errors should be handled by checking value returned by flb_malloc().

Your Environment

  • Version used:
    Current "master" branch

Additional context

See following recommendations for details:
https://wiki.sei.cmu.edu/confluence/display/c/ERR33-C.+Detect+and+handle+standard+library+errors

@yongtang
Copy link
Contributor

yongtang commented Feb 9, 2021

Thanks @raminfp , added a PR #3045 for the fix.

@edsiper
Copy link
Member

edsiper commented Feb 9, 2021

thanks, #3045 has been merged

@edsiper edsiper closed this as completed Feb 9, 2021
@abergmann
Copy link

CVE-2021-27186 was assigned to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants