-
Notifications
You must be signed in to change notification settings - Fork 14
Changed strlen to lua_strlen for producers key and value #22
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
Conversation
kafka/producer.c
Outdated
lua_pushstring(L, "key"); | ||
lua_gettable(L, -2 ); | ||
// rd_kafka will copy key so no need to worry about this cast | ||
char *key = (char *)lua_tostring(L, -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why didn't you simply use lua_tolstring
that accepts an additional argument where string will be returned.
size_t key_len = key != NULL ? lua_strlen(L, -1) : 0; | ||
char *key = (char *)lua_tolstring(L, -1, &key_len); | ||
|
||
lua_pop(L, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, as we discussed in Tarantool-ru telegram chat, this approach could lead to use-after-free (https://pgl.yoyo.org/luai/i/lua_tolstring)
Maybe we should use luaL_ref/luaL_unref here.
Also it would be great to add a test for such case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem of use after free was present before (and I suppose this is another issue), this PR just replace strlen
to lua_tolstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you are right. I don't have objections.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this approach could lead to use-after-free
@filonenko-mikhail @olegrok please confirm or deny that this issue has been fixed till the current day's release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to problem still exists
No description provided.