Skip to content

Conversation

R-omk
Copy link

@R-omk R-omk commented Jun 12, 2020

No description provided.

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);
Copy link

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);
Copy link

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.

Copy link
Author

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

Copy link

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.

Copy link
Author

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.

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

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

Successfully merging this pull request may close these issues.

3 participants