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 2017/05/14 16:39:48 UTC
[trafficserver] branch master updated: fix ts_fetch ip parse error
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 bdbcdc8 fix ts_fetch ip parse error
bdbcdc8 is described below
commit bdbcdc8286ce2dd31d1024ab211e724b93cc2cec
Author: scw00 <61...@qq.com>
AuthorDate: Wed May 10 19:50:45 2017 +0800
fix ts_fetch ip parse error
---
plugins/experimental/ts_lua/ts_lua_fetch.c | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/plugins/experimental/ts_lua/ts_lua_fetch.c b/plugins/experimental/ts_lua/ts_lua_fetch.c
index 0e3ba83..cba3b08 100644
--- a/plugins/experimental/ts_lua/ts_lua_fetch.c
+++ b/plugins/experimental/ts_lua/ts_lua_fetch.c
@@ -203,7 +203,7 @@ static int
ts_lua_fetch_one_item(lua_State *L, const char *url, size_t url_len, ts_lua_fetch_info *fi)
{
TSCont contp;
- int tb, flags, host_len, rc, port, n;
+ int tb, flags, host_len, port, n;
int cl, ht, ua;
const char *method, *key, *value, *body, *opt;
const char *addr, *ptr, *host;
@@ -253,7 +253,7 @@ ts_lua_fetch_one_item(lua_State *L, const char *url, size_t url_len, ts_lua_fetc
/* cliaddr */
memset(&clientaddr, 0, sizeof(clientaddr));
clientaddr.sin_family = AF_INET;
- rc = 0;
+ const char *p = NULL;
if (tb) {
lua_pushlstring(L, "cliaddr", sizeof("cliaddr") - 1);
@@ -261,17 +261,26 @@ ts_lua_fetch_one_item(lua_State *L, const char *url, size_t url_len, ts_lua_fetc
if (lua_isstring(L, -1)) {
addr = luaL_checklstring(L, -1, &addr_len);
- rc = sscanf(addr, "%15s:%d", ipstr, &port);
- if (rc == 2) {
+ p = strstr(addr, ":");
+ if (p && p - addr < 32) {
+ port = atoi(p + 1);
+ strncpy(ipstr, addr, p - addr);
+ ipstr[p - addr] = 0;
clientaddr.sin_port = htons(port);
- inet_aton(ipstr, (struct in_addr *)&clientaddr.sin_addr.s_addr);
+ if (!inet_aton(ipstr, (struct in_addr *)&clientaddr.sin_addr.s_addr)) {
+ p = NULL;
+ TSError("[%s] Client ip parse failed! Using defualt. [ip: %s]", TS_LUA_DEBUG_TAG, ipstr);
+ }
+ } else {
+ p = NULL;
+ TSError("[%s] Client ip parse failed! Using defualt. [addrstr: %s]", TS_LUA_DEBUG_TAG, addr);
}
}
lua_pop(L, 1);
}
- if (rc != 2) {
+ if (!p) {
clientaddr.sin_port = htons(TS_LUA_FETCH_CLIENT_PORT);
inet_aton(TS_LUA_FETCH_CLIENT_ADDRESS, (struct in_addr *)&clientaddr.sin_addr.s_addr);
}
--
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].