You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ki...@apache.org on 2021/08/14 17:47:00 UTC
[trafficserver] branch master updated: Fix crash in lua host lookup
(#8236)
This is an automated email from the ASF dual-hosted git repository.
kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 4bde2a6 Fix crash in lua host lookup (#8236)
4bde2a6 is described below
commit 4bde2a6a671e00fa77b067a52090aebb6bf3b394
Author: Kit Chan <ki...@apache.org>
AuthorDate: Sat Aug 14 10:46:47 2021 -0700
Fix crash in lua host lookup (#8236)
* Fix crash in lua host lookup
* fix typo in comment
---
plugins/lua/ts_lua_misc.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/plugins/lua/ts_lua_misc.c b/plugins/lua/ts_lua_misc.c
index 312998f..8859a17 100644
--- a/plugins/lua/ts_lua_misc.c
+++ b/plugins/lua/ts_lua_misc.c
@@ -472,13 +472,17 @@ ts_lua_host_lookup(lua_State *L)
host = luaL_checklstring(L, 1, &host_len);
- contp = TSContCreate(ts_lua_host_lookup_handler, ci->mutex);
- action = TSHostLookup(contp, host, host_len);
+ contp = TSContCreate(ts_lua_host_lookup_handler, ci->mutex);
+ ai = ts_lua_async_create_item(contp, ts_lua_host_lookup_cleanup, NULL, ci);
- ai = ts_lua_async_create_item(contp, ts_lua_host_lookup_cleanup, (void *)action, ci);
TSContDataSet(contp, ai);
+ action = TSHostLookup(contp, host, host_len);
+ if (!TSActionDone(action)) {
+ ai->data = (void *)action;
+ return lua_yield(L, 0);
+ }
- return lua_yield(L, 0);
+ return 1;
}
static int
@@ -486,16 +490,24 @@ ts_lua_host_lookup_handler(TSCont contp, TSEvent event, void *edata)
{
ts_lua_async_item *ai;
ts_lua_cont_info *ci;
- struct sockaddr const *addr;
char cip[128];
lua_State *L;
ts_lua_coroutine *crt;
+ unsigned int resume;
ai = TSContDataGet(contp);
ci = ai->cinfo;
crt = &ci->routine;
L = crt->lua;
+ // find out if need to resume luaVM before async item cleanup
+ if (ai->data != NULL) {
+ resume = 1;
+ } else {
+ resume = 0;
+ }
+
+ // async item cleanup
ai->data = NULL;
ts_lua_host_lookup_cleanup(ai);
@@ -505,8 +517,8 @@ ts_lua_host_lookup_handler(TSCont contp, TSEvent event, void *edata)
} else if (!edata) {
lua_pushnil(L);
} else {
- TSHostLookupResult result = (TSHostLookupResult)edata;
- addr = TSHostLookupResultAddrGet(result);
+ TSHostLookupResult result = (TSHostLookupResult)edata;
+ struct sockaddr const *addr = TSHostLookupResultAddrGet(result);
if (addr->sa_family == AF_INET) {
inet_ntop(AF_INET, (const void *)&((struct sockaddr_in *)addr)->sin_addr, cip, sizeof(cip));
} else {
@@ -515,7 +527,9 @@ ts_lua_host_lookup_handler(TSCont contp, TSEvent event, void *edata)
lua_pushstring(L, cip);
}
- TSContCall(ci->contp, TS_LUA_EVENT_COROUTINE_CONT, (void *)1);
+ if (resume == 1) {
+ TSContCall(ci->contp, TS_LUA_EVENT_COROUTINE_CONT, (void *)1);
+ }
return 0;
}