From: Willy Tarreau Date: Thu, 10 Mar 2016 15:28:58 +0000 (+0100) Subject: MINOR: sample: always set a new sample's owner before evaluating it X-Git-Tag: v1.7-dev2~61 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7560dd4b6a4b4f8ee2c002cd3ecb36e854cb8de1;p=thirdparty%2Fhaproxy.git MINOR: sample: always set a new sample's owner before evaluating it Some functions like sample_conv_var2smp(), var_get_byname(), and var_set_byname() directly or indirectly need to access the current stream and/or session and must find it in the sample itself and not as a distinct argument. Thus we first need to call smp_set_owner() prior to each such calls. --- diff --git a/src/hlua.c b/src/hlua.c index 2ed6f525d7..584ad9b346 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -4568,6 +4568,7 @@ __LJMP static int hlua_set_var(lua_State *L) hlua_lua2smp(L, 3, &smp); /* Store the sample in a variable. */ + smp_set_owner(&smp, htxn->p, htxn->s->sess, htxn->s, htxn->dir & SMP_OPT_DIR); vars_set_by_name(name, len, htxn->s, &smp); return 0; } @@ -4587,6 +4588,7 @@ __LJMP static int hlua_get_var(lua_State *L) htxn = MAY_LJMP(hlua_checktxn(L, 1)); name = MAY_LJMP(luaL_checklstring(L, 2, &len)); + smp_set_owner(&smp, htxn->p, htxn->s->sess, htxn->s, htxn->dir & SMP_OPT_DIR); if (!vars_get_by_name(name, len, htxn->s, &smp)) { lua_pushnil(L); return 1; diff --git a/src/sample.c b/src/sample.c index 7c2d9058f0..6dc62fbc2f 100644 --- a/src/sample.c +++ b/src/sample.c @@ -2100,6 +2100,7 @@ static int sample_conv_binary_and(const struct arg *arg_p, struct sample *smp, v { struct sample tmp; + smp_set_owner(&tmp, smp->px, smp->sess, smp->strm, smp->opt); if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; smp->data.u.sint &= tmp.data.u.sint; @@ -2113,6 +2114,7 @@ static int sample_conv_binary_or(const struct arg *arg_p, struct sample *smp, vo { struct sample tmp; + smp_set_owner(&tmp, smp->px, smp->sess, smp->strm, smp->opt); if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; smp->data.u.sint |= tmp.data.u.sint; @@ -2126,6 +2128,7 @@ static int sample_conv_binary_xor(const struct arg *arg_p, struct sample *smp, v { struct sample tmp; + smp_set_owner(&tmp, smp->px, smp->sess, smp->strm, smp->opt); if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; smp->data.u.sint ^= tmp.data.u.sint; @@ -2165,6 +2168,7 @@ static int sample_conv_arith_add(const struct arg *arg_p, struct sample *smp, vo { struct sample tmp; + smp_set_owner(&tmp, smp->px, smp->sess, smp->strm, smp->opt); if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; smp->data.u.sint = arith_add(smp->data.u.sint, tmp.data.u.sint); @@ -2179,6 +2183,7 @@ static int sample_conv_arith_sub(const struct arg *arg_p, { struct sample tmp; + smp_set_owner(&tmp, smp->px, smp->sess, smp->strm, smp->opt); if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; @@ -2211,6 +2216,7 @@ static int sample_conv_arith_mul(const struct arg *arg_p, struct sample tmp; long long int c; + smp_set_owner(&tmp, smp->px, smp->sess, smp->strm, smp->opt); if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; @@ -2254,6 +2260,7 @@ static int sample_conv_arith_div(const struct arg *arg_p, { struct sample tmp; + smp_set_owner(&tmp, smp->px, smp->sess, smp->strm, smp->opt); if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; @@ -2281,6 +2288,7 @@ static int sample_conv_arith_mod(const struct arg *arg_p, { struct sample tmp; + smp_set_owner(&tmp, smp->px, smp->sess, smp->strm, smp->opt); if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0;