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

[BUG] luaL_buffinit在栈上添加了lightuserdata,导致bson.binary的栈失衡,引发功能错误 #1388

Closed
zaxbbun opened this issue Apr 19, 2021 · 1 comment

Comments

@zaxbbun
Copy link
Contributor

zaxbbun commented Apr 19, 2021

LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {

LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {
  B->L = L;
  B->b = B->init.b;
  B->n = 0;
  B->size = LUAL_BUFFERSIZE;
  lua_pushlightuserdata(L, (void*)B);  /* push placeholder */
}

luaL_buffinit 引入了

  lua_pushlightuserdata(L, (void*)B);  /* push placeholder */

导致栈失衡

lbinary(lua_State *L) {


static int
lbinary(lua_State *L) {
	lua_settop(L,1);
	luaL_Buffer b;
	luaL_buffinit(L, &b);
	luaL_addchar(&b, 0);
	luaL_addchar(&b, BSON_BINARY);
	luaL_addchar(&b, 0);	// sub type
	luaL_addvalue(&b);   // 此处使用的是-1本意为传入的参数,但是却使用了luaL_buffinit 引入的lightuserdata 导致功能错误
	luaL_pushresult(&b);

	return 1;
}

由于不清楚是否还引入了其它的错误 需要 @cloudwu 确认下

@cloudwu
Copy link
Owner

cloudwu commented Apr 19, 2021

谢谢。我检查了其它类似的地方,应该没有问题。

ps. 前几天在邮件列表看到了类似的问题:http://lua-users.org/lists/lua-l/2021-04/msg00027.html 这次 lua 5.4.3 升级,应该有很多历史库会有这类 bug 。

wangyi0226 added a commit to wangyi0226/skynet that referenced this issue Apr 21, 2021
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

2 participants