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

flb_utils: fix out of bounds write on invalid utf-8 #875

Merged
merged 1 commit into from
Nov 2, 2018
Merged

flb_utils: fix out of bounds write on invalid utf-8 #875

merged 1 commit into from
Nov 2, 2018

Conversation

chlunde
Copy link
Contributor

@chlunde chlunde commented Oct 31, 2018

In flb_utils_write_str, written and *off could be set
to an incorrect large value on invalid UTF-8 input.

Later, this would lead to an out of bounds write when
nul-terminating the string:

Invalid write of size 1
   at 0x44378B: flb_msgpack_to_json (in /build/bin/fluent-bit)
   by 0x443B78: flb_msgpack_raw_to_json_str (in /build/bin/fluent-bit)
   by 0x47576D: kafka_rest_format (in /build/bin/fluent-bit)
   by 0x4758E9: cb_kafka_flush (in /build/bin/fluent-bit)
   by 0x434A71: output_pre_cb_flush (in /build/bin/fluent-bit)
   by 0x50DF26: co_init (in /build/bin/fluent-bit)
 Address 0x4d9985e is on thread 1's stack

Input file (base64 encoded):

MAowCjAwCjAwADAKMDAwMDAK/wowCjAwCoAK

In flb_utils_write_str, written and *off could be set
to an incorrect large value on invalid UTF-8 input.

Later, this would lead to an out of bounds write when
nul-terminating the string:

    Invalid write of size 1
       at 0x44378B: flb_msgpack_to_json (in /build/bin/fluent-bit)
       by 0x443B78: flb_msgpack_raw_to_json_str (in /build/bin/fluent-bit)
       by 0x47576D: kafka_rest_format (in /build/bin/fluent-bit)
       by 0x4758E9: cb_kafka_flush (in /build/bin/fluent-bit)
       by 0x434A71: output_pre_cb_flush (in /build/bin/fluent-bit)
       by 0x50DF26: co_init (in /build/bin/fluent-bit)
     Address 0x4d9985e is on thread 1's stack

Input file (base64 encoded):

    MAowCjAwCjAwADAKMDAwMDAK/wowCjAwCoAK

Signed-off-by: Carl Henrik Lunde <[email protected]>
@chlunde
Copy link
Contributor Author

chlunde commented Oct 31, 2018

@edsiper please double check this, but I cannot see why written is set initially, and if the loop terminates before setting written again at least once we run into this issue. This also means buffers are often seen as to small even if they were large enough.

@edsiper
Copy link
Member

edsiper commented Nov 2, 2018

taking a look now...

@edsiper edsiper self-assigned this Nov 2, 2018
src/flb_utils.c Show resolved Hide resolved
@edsiper edsiper merged commit bc66694 into fluent:master Nov 2, 2018
@edsiper
Copy link
Member

edsiper commented Nov 2, 2018

thanks for troubleshoot and fix this

edsiper pushed a commit that referenced this pull request Nov 2, 2018
In flb_utils_write_str, written and *off could be set
to an incorrect large value on invalid UTF-8 input.

Later, this would lead to an out of bounds write when
nul-terminating the string:

    Invalid write of size 1
       at 0x44378B: flb_msgpack_to_json (in /build/bin/fluent-bit)
       by 0x443B78: flb_msgpack_raw_to_json_str (in /build/bin/fluent-bit)
       by 0x47576D: kafka_rest_format (in /build/bin/fluent-bit)
       by 0x4758E9: cb_kafka_flush (in /build/bin/fluent-bit)
       by 0x434A71: output_pre_cb_flush (in /build/bin/fluent-bit)
       by 0x50DF26: co_init (in /build/bin/fluent-bit)
     Address 0x4d9985e is on thread 1's stack

Input file (base64 encoded):

    MAowCjAwCjAwADAKMDAwMDAK/wowCjAwCoAK

Signed-off-by: Carl Henrik Lunde <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants