-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[all versions] off by one error in sds string lib flb_sds_printf triggered by specific conditions #7143
Comments
Will submit fix PR from above commit very soon. |
See relevant similar code in upstream/original SDS library: https://github.com/antirez/sds/blob/master/sds.c#L559 Looks like that logic recently changed from a much different older code: antirez/sds@a9a03bb https://github.com/antirez/sds/blame/fb463145c9c245636feb28b5aac0fc897e16f67e/sds.c#L543 |
Thanks for the links @nokute78, I was sure I had verified this issue with someone else in the past and thought it would've definitely been fixed but I guess it never took off. It's a legit bug the patches are wrong because
Which in the case of the 64 character string would mean passing 0 as the increment size to the function but considering that the function adds 1 character for the terminator it works. If the patch is applied as is the buffer would go from 80 characters to 145 whereas with the proper change it would go from 80 to 81. |
@leonardo-albertovich flb_sds_increase is used twice in the function, right now the first usage increases the alloc by 64... should I also change that to increase it to 64?? |
Sure. |
@leonardo-albertovich sorry actually I think it should be:
We check the avail in the condition which makes sense since the some of the alloc might already be taken by an existing string. |
I will add unit test for this bug as well |
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
The test here repros it: PettitWesley@8075d6e |
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
You are right, I just approved your PRs, thanks a lot! |
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days. Maintainers can add the |
This issue was closed because it has been stalled for 5 days with no activity. |
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
Signed-off-by: Wesley Pettit <[email protected]>
Discovered here in a conversation on the linked bug fix: #7129 (comment)
flb_sds_printf
will re-alloc if needed: https://github.com/fluent/fluent-bit/blob/master/src/flb_sds.c#L437However, note the inclusive and exclusive wording in the docs below:
https://linux.die.net/man/3/vsnprintf
So the condition on re-alloc'ing the string in the code should be
>=
and the re-alloc should be +1 larger I think.Demo
branch: https://github.com/PettitWesley/fluent-bit/commits/sds-off-by-1-demo
See the demo here: PettitWesley@57925b8
And fix here: PettitWesley@a333eeb
unit test here: PettitWesley@8075d6e
Conditions that cause it
See the
len
logic here: https://github.com/fluent/fluent-bit/blob/master/src/flb_sds.c#L411I think to cause this bug to surface, the variables used in the format must be longer than the format in just the right way to get
vsnprintf
returned size that's equal to the currently alloc'd size.This is what I used in the demo above:
The text was updated successfully, but these errors were encountered: