Re: stats webpage crash, htx and scope filter, [PATCH] REGTEST is included

2019-01-17 Thread Christopher Faulet

Le 16/01/2019 à 22:25, Willy Tarreau a écrit :

Hi Pieter,

On Wed, Jan 16, 2019 at 08:44:58PM +0100, PiBa-NL wrote:

Hi Willy, Christopher,
Op 16-1-2019 om 17:32 schreef Willy Tarreau:

On Wed, Jan 16, 2019 at 02:28:56PM +0100, Christopher Faulet wrote:

here is a new patch, again. Willy, I hope it will be good for the
release 1.9.2.

This one works :).


Great, thank you!


Op 14-1-2019 om 11:17 schreef Christopher Faulet:

If it's ok for you, I'll also merge your regtest.


Can you add the regtest as well into the git repo?


I'm not sure which one it is, I'll let Christopher take care of it.



I merged the regtest. Thanks Pieter !

--
Christopher Faulet



Re: stats webpage crash, htx and scope filter, [PATCH] REGTEST is included

2019-01-16 Thread Willy Tarreau
Hi Pieter,

On Wed, Jan 16, 2019 at 08:44:58PM +0100, PiBa-NL wrote:
> Hi Willy, Christopher,
> Op 16-1-2019 om 17:32 schreef Willy Tarreau:
> > On Wed, Jan 16, 2019 at 02:28:56PM +0100, Christopher Faulet wrote:
> > > here is a new patch, again. Willy, I hope it will be good for the
> > > release 1.9.2.
> This one works :).

Great, thank you!

> Op 14-1-2019 om 11:17 schreef Christopher Faulet:
> > If it's ok for you, I'll also merge your regtest.
> 
> Can you add the regtest as well into the git repo?

I'm not sure which one it is, I'll let Christopher take care of it.

Thanks,
Willy



Re: stats webpage crash, htx and scope filter, [PATCH] REGTEST is included

2019-01-16 Thread PiBa-NL

Hi Willy, Christopher,
Op 16-1-2019 om 17:32 schreef Willy Tarreau:

On Wed, Jan 16, 2019 at 02:28:56PM +0100, Christopher Faulet wrote:

here is a new patch, again. Willy, I hope it will be good for the
release 1.9.2.

This one works :).

OK so I've mergd it now, thank you!
Willy


Op 14-1-2019 om 11:17 schreef Christopher Faulet:

If it's ok for you, I'll also merge your regtest.


Can you add the regtest as well into the git repo?

Regards,
PiBa-NL (Pieter)




Re: stats webpage crash, htx and scope filter, [PATCH] REGTEST is included

2019-01-16 Thread Willy Tarreau
On Wed, Jan 16, 2019 at 02:28:56PM +0100, Christopher Faulet wrote:
> Rah ! I'll probably need some rest. I've done my tests without the HTX
> enabled... It's a bit embarrassing and not really responsible.

Let's say it's due to uncaught -EKIDSAROUND :-)

> Anyway, here is a new patch, again. Willy, I hope it will be good for the
> release 1.9.2.

OK so I've mergd it now, thank you!

Willy



Re: stats webpage crash, htx and scope filter, [PATCH] REGTEST is included

2019-01-16 Thread Christopher Faulet

Le 15/01/2019 à 21:07, PiBa-NL a écrit :

Hi Christopher,

Op 15-1-2019 om 10:48 schreef Christopher Faulet:

Le 14/01/2019 à 21:53, PiBa-NL a écrit :

Hi Christopher,

Op 14-1-2019 om 11:17 schreef Christopher Faulet:

Le 12/01/2019 à 23:23, PiBa-NL a écrit :

Hi List,

I've configured haproxy with htx and when i try to filter the stats
webpage.
Sending this request: "GET /?;csv;scope=b1" to '2.0-dev0-762475e
2019/01/10' it will crash with the trace below.
1.9.0 and 1.9.1 are also affected.

Can someone take a look? Thanks in advance.

A regtest is attached that reproduces the behavior, and which i think
could be included into the haproxy repository.



Pieter,

Here is the patch that should fix this issue. This was "just" an
oversight when the stats applet has been adapted to support the HTX.

If it's ok for you, I'll also merge your regtest.

Thanks


It seems the patch did not change/fix the crash.? Below looks pretty
much the same as previously. Did i fail to apply the patch properly.? It
seems to have 'applied' properly checking a few lines of the touched
code manually. As for the regtest, yes please merge that if its okay
as-is, perhaps after the fix is also ready :).



Hi Pieter,

Sorry, I made my patch too quickly. It seemed ok, but obviously not...
This new one should do the trick.


Well.. 'something' changed, still crashing though.. but at a different
place.



Rah ! I'll probably need some rest. I've done my tests without the HTX 
enabled... It's a bit embarrassing and not really responsible.


Anyway, here is a new patch, again. Willy, I hope it will be good for 
the release 1.9.2.


--
Christopher Faulet
>From cacd3205bbe5c1a0bf123631178b61e1f6e9ffc1 Mon Sep 17 00:00:00 2001
From: Christopher Faulet 
Date: Mon, 14 Jan 2019 11:07:34 +0100
Subject: [PATCH] BUG/MEDIUM: stats: Get the rigth scope pointer depending on
 HTX is used or not

For HTX streams, the scope pointer is relative to the URI in the start-line. But
for streams using the legacy HTTP representation, the scope pointer is relative
to the beginning of output data in the channel's buffer. So we must be carefull
to use the right one depending on the HTX is used or not.

Because the start-line is used to get de scope pointer, it is important to keep
it after the parsing of post paramters. So now, instead of removing blocks when
read in the function stats_process_http_post(), we just move on next, leaving it
in the HTX message.

Thanks to Pieter (PiBa-NL) to report this bug.

This patch must be backported to 1.9.
---
 src/proto_htx.c |  4 ++--
 src/stats.c | 62 ++---
 2 files changed, 45 insertions(+), 21 deletions(-)

diff --git a/src/proto_htx.c b/src/proto_htx.c
index 236bfd04d..9fa820653 100644
--- a/src/proto_htx.c
+++ b/src/proto_htx.c
@@ -4887,8 +4887,8 @@ static int htx_handle_stats(struct stream *s, struct channel *req)
 
 			h += strlen(STAT_SCOPE_INPUT_NAME) + 1;
 			h2 = h;
-			appctx->ctx.stats.scope_str = h2 - s->txn->uri;
-			while (h <= end) {
+			appctx->ctx.stats.scope_str = h2 - HTX_SL_REQ_UPTR(sl);
+			while (h < end) {
 if (*h == ';' || *h == '&' || *h == ' ')
 	break;
 itx++;
diff --git a/src/stats.c b/src/stats.c
index ebd95d3f0..a7c12e120 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -55,6 +55,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -257,6 +258,23 @@ static int stats_putchk(struct channel *chn, struct htx *htx, struct buffer *chk
 	return 1;
 }
 
+static const char *stats_scope_ptr(struct appctx *appctx, struct stream_interface *si)
+{
+	const char *p;
+
+	if (IS_HTX_STRM(si_strm(si))) {
+		struct channel *req = si_oc(si);
+		struct htx *htx = htxbuf(&req->buf);
+		struct ist uri = htx_sl_req_uri(http_find_stline(htx));
+
+		p = uri.ptr;
+	}
+	else
+		p = co_head(si_oc(si));
+
+	return p + appctx->ctx.stats.scope_str;
+}
+
 /*
  * http_stats_io_handler()
  * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML
@@ -1912,8 +1930,10 @@ static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px
 		/* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
 		scope_txt[0] = 0;
 		if (appctx->ctx.stats.scope_len) {
+			const char *scope_ptr = stats_scope_ptr(appctx, si);
+
 			strcpy(scope_txt, STAT_SCOPE_PATTERN);
-			memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
+			memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
 			scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
 		}
 
@@ -2075,9 +2095,12 @@ int stats_dump_proxy_to_buffer(struct stream_interface *si, struct htx *htx,
 		/* if the user has requested a limited output and the proxy
 		 * name does not match, skip it.
 		 */
-		if (appctx->ctx.stats.scope_len &&
-		strnistr(px->id, strlen(px->id), co_head(si_oc(si

Re: stats webpage crash, htx and scope filter, [PATCH] REGTEST is included

2019-01-15 Thread PiBa-NL

Hi Christopher,

Op 15-1-2019 om 10:48 schreef Christopher Faulet:

Le 14/01/2019 à 21:53, PiBa-NL a écrit :

Hi Christopher,

Op 14-1-2019 om 11:17 schreef Christopher Faulet:

Le 12/01/2019 à 23:23, PiBa-NL a écrit :

Hi List,

I've configured haproxy with htx and when i try to filter the stats
webpage.
Sending this request: "GET /?;csv;scope=b1" to '2.0-dev0-762475e
2019/01/10' it will crash with the trace below.
1.9.0 and 1.9.1 are also affected.

Can someone take a look? Thanks in advance.

A regtest is attached that reproduces the behavior, and which i think
could be included into the haproxy repository.



Pieter,

Here is the patch that should fix this issue. This was "just" an
oversight when the stats applet has been adapted to support the HTX.

If it's ok for you, I'll also merge your regtest.

Thanks


It seems the patch did not change/fix the crash.? Below looks pretty
much the same as previously. Did i fail to apply the patch properly.? It
seems to have 'applied' properly checking a few lines of the touched
code manually. As for the regtest, yes please merge that if its okay
as-is, perhaps after the fix is also ready :).



Hi Pieter,

Sorry, I made my patch too quickly. It seemed ok, but obviously not... 
This new one should do the trick.


Well.. 'something' changed, still crashing though.. but at a different 
place.


Regards,
PiBa-NL (Pieter)

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x004d3770 in htx_sl_p2 (sl=0x0) at include/common/htx.h:237
237 return ist2(HTX_SL_P2_PTR(sl), HTX_SL_P2_LEN(sl));
(gdb) bt full
#0  0x004d3770 in htx_sl_p2 (sl=0x0) at include/common/htx.h:237
No locals.
#1  0x004d3665 in htx_sl_req_uri (sl=0x0) at 
include/common/htx.h:252

No locals.
#2  0x004d1125 in stats_scope_ptr (appctx=0x802678540, 
si=0x8026416d8) at src/stats.c:268

    req = 0x802641410
    htx = 0x80271df80
    uri = {ptr = 0x60932e  
"H\213E\320H\211E\370H\213E\370H\201\304\260", len = 4304914720}
    p = 0x4802631048 0x4802631048>
#3  0x004d8505 in stats_send_htx_redirect (si=0x8026416d8, 
htx=0x8027c8e40) at src/stats.c:3162

    scope_ptr = 0x5f80f5 <__pool_get_first+21> "H\211E\310H\203}\310"
    scope_txt = 
"\000\342\377\377\377\177\000\000\351}M\000\000\000\000\000x\024d\002\b\000\000\000x\024d\002"

    s = 0x802641400
    uri = 0x802638000
    appctx = 0x802678540
    sl = 0x8027c8e40
    flags = 8
#4  0x004d60fb in htx_stats_io_handler (appctx=0x802678540) at 
src/stats.c:3337

    si = 0x8026416d8
    s = 0x802641400
    req = 0x802641410
    res = 0x802641470
    req_htx = 0x8027c8e40
    res_htx = 0x8027c8e40
#5  0x004d2d36 in http_stats_io_handler (appctx=0x802678540) at 
src/stats.c:3393

    si = 0x8026416d8
    s = 0x802641400
    req = 0x802641410
    res = 0x802641470
#6  0x005f7d5f in task_run_applet (t=0x802656780, 
context=0x802678540, state=16385) at src/applet.c:85

    app = 0x802678540
    si = 0x8026416d8
#7  0x005f3023 in process_runnable_tasks () at src/task.c:435
    t = 0x802656780
    state = 16385
    ctx = 0x802678540
    process = 0x5f7cc0 
    t = 0x802656780
    max_processed = 200
#8  0x00516ca2 in run_poll_loop () at src/haproxy.c:2620
    next = 0
    exp = 1394283990
#9  0x005138f8 in run_thread_poll_loop (data=0x8026310e8) at 
src/haproxy.c:2685

    start_lock = 0
    ptif = 0x936d40 
    ptdf = 0x0
#10 0x0050ff26 in main (argc=4, argv=0x7fffeb08) at 
src/haproxy.c:3314

    tids = 0x8026310e8
    threads = 0x8026310f0
    i = 1
    old_sig = {__bits = {0, 0, 0, 0}}
    blocked_sig = {__bits = {4227856759, 4294967295, 4294967295, 
4294967295}}

    err = 0
    retry = 200
    limit = {rlim_cur = 4051, rlim_max = 4051}
    errmsg = 
"\000\353\377\377\377\177\000\000\060\353\377\377\377\177\000\000\b\353\377\377\377\177\000\000\004\000\000\000\000\000\000\000\376\310\311\070\333\207d\000`9\224\000\000\000\000\000\000\353\377\377\377\177\000\000\060\353\377\377\377\177\000\000\b\353\377\377\377\177\000\000\004\000\000\000\000\000\000\000\240\352\377\377\377\177\000\000R\201\000\002\b\000\000\000\001\000\000"

    pidfd = -1




Re: stats webpage crash, htx and scope filter, [PATCH] REGTEST is included

2019-01-15 Thread Christopher Faulet

Le 14/01/2019 à 21:53, PiBa-NL a écrit :

Hi Christopher,

Op 14-1-2019 om 11:17 schreef Christopher Faulet:

Le 12/01/2019 à 23:23, PiBa-NL a écrit :

Hi List,

I've configured haproxy with htx and when i try to filter the stats
webpage.
Sending this request: "GET /?;csv;scope=b1" to '2.0-dev0-762475e
2019/01/10' it will crash with the trace below.
1.9.0 and 1.9.1 are also affected.

Can someone take a look? Thanks in advance.

A regtest is attached that reproduces the behavior, and which i think
could be included into the haproxy repository.



Pieter,

Here is the patch that should fix this issue. This was "just" an
oversight when the stats applet has been adapted to support the HTX.

If it's ok for you, I'll also merge your regtest.

Thanks


It seems the patch did not change/fix the crash.? Below looks pretty
much the same as previously. Did i fail to apply the patch properly.? It
seems to have 'applied' properly checking a few lines of the touched
code manually. As for the regtest, yes please merge that if its okay
as-is, perhaps after the fix is also ready :).



Hi Pieter,

Sorry, I made my patch too quickly. It seemed ok, but obviously not... 
This new one should do the trick.


--
Christopher Faulet
>From 94244a5a994904f7dedc261d78ca86dfabfe6bd4 Mon Sep 17 00:00:00 2001
From: Christopher Faulet 
Date: Mon, 14 Jan 2019 11:07:34 +0100
Subject: [PATCH] BUG/MEDIUM: stats: Get the rigth scope pointer depending on
 HTX is used or not

For HTX streams, the scope pointer is relative to the URI in the start-line. But
for streams using the legacy HTTP representation, the scope pointer is relative
to the beginning of output data in the channel's buffer. So we must be carefull
to use the right one depending on the HTX is used or not.

Thanks to Pieter (PiBa-NL) to report this bug.

This patch must be backported to 1.9.
---
 src/proto_htx.c |  4 ++--
 src/stats.c | 40 +---
 2 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/src/proto_htx.c b/src/proto_htx.c
index 236bfd04d..9fa820653 100644
--- a/src/proto_htx.c
+++ b/src/proto_htx.c
@@ -4887,8 +4887,8 @@ static int htx_handle_stats(struct stream *s, struct channel *req)
 
 			h += strlen(STAT_SCOPE_INPUT_NAME) + 1;
 			h2 = h;
-			appctx->ctx.stats.scope_str = h2 - s->txn->uri;
-			while (h <= end) {
+			appctx->ctx.stats.scope_str = h2 - HTX_SL_REQ_UPTR(sl);
+			while (h < end) {
 if (*h == ';' || *h == '&' || *h == ' ')
 	break;
 itx++;
diff --git a/src/stats.c b/src/stats.c
index ebd95d3f0..d5b8d5cb8 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -55,6 +55,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -257,6 +258,23 @@ static int stats_putchk(struct channel *chn, struct htx *htx, struct buffer *chk
 	return 1;
 }
 
+static const char *stats_scope_ptr(struct appctx *appctx, struct stream_interface *si)
+{
+	const char *p;
+
+	if (IS_HTX_STRM(si_strm(si))) {
+		struct channel *req = si_oc(si);
+		struct htx *htx = htxbuf(&req->buf);
+		struct ist uri = htx_sl_req_uri(http_find_stline(htx));
+
+		p = uri.ptr;
+	}
+	else
+		p = co_head(si_oc(si));
+
+	return p + appctx->ctx.stats.scope_str;
+}
+
 /*
  * http_stats_io_handler()
  * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML
@@ -1912,8 +1930,10 @@ static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px
 		/* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
 		scope_txt[0] = 0;
 		if (appctx->ctx.stats.scope_len) {
+			const char *scope_ptr = stats_scope_ptr(appctx, si);
+
 			strcpy(scope_txt, STAT_SCOPE_PATTERN);
-			memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
+			memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
 			scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
 		}
 
@@ -2075,9 +2095,12 @@ int stats_dump_proxy_to_buffer(struct stream_interface *si, struct htx *htx,
 		/* if the user has requested a limited output and the proxy
 		 * name does not match, skip it.
 		 */
-		if (appctx->ctx.stats.scope_len &&
-		strnistr(px->id, strlen(px->id), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len) == NULL)
-			return 1;
+		if (appctx->ctx.stats.scope_len) {
+			const char *scope_ptr = stats_scope_ptr(appctx, si);
+
+			if (strnistr(px->id, strlen(px->id), scope_ptr, appctx->ctx.stats.scope_len) == NULL)
+return 1;
+		}
 
 		if ((appctx->ctx.stats.flags & STAT_BOUND) &&
 		(appctx->ctx.stats.iid != -1) &&
@@ -2347,6 +2370,7 @@ static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *u
 	struct appctx *appctx = __objt_appctx(si->end);
 	unsigned int up = (now.tv_sec - start_date.tv_sec);
 	char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
+	const char *scope_ptr = stats

Re: stats webpage crash, htx and scope filter, [PATCH] REGTEST is included

2019-01-14 Thread PiBa-NL

Hi Christopher,

Op 14-1-2019 om 11:17 schreef Christopher Faulet:

Le 12/01/2019 à 23:23, PiBa-NL a écrit :

Hi List,

I've configured haproxy with htx and when i try to filter the stats 
webpage.

Sending this request: "GET /?;csv;scope=b1" to '2.0-dev0-762475e
2019/01/10' it will crash with the trace below.
1.9.0 and 1.9.1 are also affected.

Can someone take a look? Thanks in advance.

A regtest is attached that reproduces the behavior, and which i think
could be included into the haproxy repository.



Pieter,

Here is the patch that should fix this issue. This was "just" an 
oversight when the stats applet has been adapted to support the HTX.


If it's ok for you, I'll also merge your regtest.

Thanks


It seems the patch did not change/fix the crash.? Below looks pretty 
much the same as previously. Did i fail to apply the patch properly.? It 
seems to have 'applied' properly checking a few lines of the touched 
code manually. As for the regtest, yes please merge that if its okay 
as-is, perhaps after the fix is also ready :).


Regards,
PiBa-NL (Pieter)

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x005658e7 in strnistr (str1=0x802631048 "fe1", len_str1=3, 
str2=0x271dfcc , 
len_str2=3) at src/standard.c:3657

3657    while (toupper(*start) != toupper(*str2)) {
(gdb) bt full
#0  0x005658e7 in strnistr (str1=0x802631048 "fe1", len_str1=3, 
str2=0x271dfcc , 
len_str2=3) at src/standard.c:3657

    pptr = 0x271dfcc 
    sptr = 0x6995d3 "text/plain"
    start = 0x802631048 "fe1"
    slen = 3
    plen = 3
    tmp1 = 0
    tmp2 = 4294958728
#1  0x004d09ff in stats_dump_proxy_to_buffer (si=0x8026416d8, 
htx=0x8027c8e40, px=0x8026b3c00, uri=0x802638000) at src/stats.c:2087
    scope_ptr = 0x271dfcc 0x271dfcc>

    appctx = 0x802678380
    s = 0x802641400
    rep = 0x802641470
    sv = 0x8027c8e40
    svs = 0x343e1e0
    l = 0x4d3a8f 
    flags = 0
#2  0x004d49e9 in stats_dump_stat_to_buffer (si=0x8026416d8, 
htx=0x8027c8e40, uri=0x802638000) at src/stats.c:2664





Re: stats webpage crash, htx and scope filter, [PATCH] REGTEST is included

2019-01-14 Thread Christopher Faulet

Le 12/01/2019 à 23:23, PiBa-NL a écrit :

Hi List,

I've configured haproxy with htx and when i try to filter the stats webpage.
Sending this request: "GET /?;csv;scope=b1" to '2.0-dev0-762475e
2019/01/10' it will crash with the trace below.
1.9.0 and 1.9.1 are also affected.

Can someone take a look? Thanks in advance.

A regtest is attached that reproduces the behavior, and which i think
could be included into the haproxy repository.



Pieter,

Here is the patch that should fix this issue. This was "just" an 
oversight when the stats applet has been adapted to support the HTX.


If it's ok for you, I'll also merge your regtest.

Thanks
--
Christopher Faulet
>From d09c87cf3d261b42f02671b3ddf2cbc36b7e1916 Mon Sep 17 00:00:00 2001
From: Christopher Faulet 
Date: Mon, 14 Jan 2019 11:07:34 +0100
Subject: [PATCH] BUG/MEDIUM: stats: Get the rigth scope pointer depending on
 HTX is used or not

For HTX streams, the scope pointer is relative to the TXN uri. But for streams
using the legacy HTTP representation, the scope pointer is relative to the
beginning of output data in the channel's buffer. So we must be carefull to use
the right one depending on the HTX is used or not.

Thanks to Pieter (PiBa-NL) to report this bug.

This patch must be backported to 1.9.
---
 src/stats.c | 26 +++---
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/stats.c b/src/stats.c
index ebd95d3f0..ee375af6f 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -1912,8 +1912,12 @@ static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px
 		/* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
 		scope_txt[0] = 0;
 		if (appctx->ctx.stats.scope_len) {
+			char *scope_ptr = (IS_HTX_STRM(si_strm(si))
+	   ? si_strm(si)->txn->uri  + appctx->ctx.stats.scope_str
+	   : co_head(si_oc(si))  + appctx->ctx.stats.scope_str);
+
 			strcpy(scope_txt, STAT_SCOPE_PATTERN);
-			memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
+			memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
 			scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
 		}
 
@@ -2075,9 +2079,14 @@ int stats_dump_proxy_to_buffer(struct stream_interface *si, struct htx *htx,
 		/* if the user has requested a limited output and the proxy
 		 * name does not match, skip it.
 		 */
-		if (appctx->ctx.stats.scope_len &&
-		strnistr(px->id, strlen(px->id), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len) == NULL)
-			return 1;
+		if (appctx->ctx.stats.scope_len) {
+			char *scope_ptr = (IS_HTX_STRM(si_strm(si))
+	   ? si_strm(si)->txn->uri  + appctx->ctx.stats.scope_str
+	   : co_head(si_oc(si))  + appctx->ctx.stats.scope_str);
+
+			if (strnistr(px->id, strlen(px->id), scope_ptr, appctx->ctx.stats.scope_len) == NULL)
+return 1;
+		}
 
 		if ((appctx->ctx.stats.flags & STAT_BOUND) &&
 		(appctx->ctx.stats.iid != -1) &&
@@ -2347,6 +2356,9 @@ static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *u
 	struct appctx *appctx = __objt_appctx(si->end);
 	unsigned int up = (now.tv_sec - start_date.tv_sec);
 	char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
+	char *scope_ptr = (IS_HTX_STRM(si_strm(si))
+			   ? si_strm(si)->txn->uri  + appctx->ctx.stats.scope_str
+			   : co_head(si_oc(si))  + appctx->ctx.stats.scope_str);
 
 	/* WARNING! this has to fit the first packet too.
 	 * We are around 3.5 kB, add adding entries will
@@ -2405,7 +2417,7 @@ static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *u
 	  );
 
 	/* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
-	memcpy(scope_txt, co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
+	memcpy(scope_txt, scope_ptr, appctx->ctx.stats.scope_len);
 	scope_txt[appctx->ctx.stats.scope_len] = '\0';
 
 	chunk_appendf(&trash,
@@ -2417,7 +2429,7 @@ static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *u
 	scope_txt[0] = 0;
 	if (appctx->ctx.stats.scope_len) {
 		strcpy(scope_txt, STAT_SCOPE_PATTERN);
-		memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
+		memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
 		scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
 	}
 
@@ -3136,7 +3148,7 @@ static int stats_send_htx_redirect(struct stream_interface *si, struct htx *htx)
 	scope_txt[0] = 0;
 	if (appctx->ctx.stats.scope_len) {
 		strcpy(scope_txt, STAT_SCOPE_PATTERN);
-		memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
+		memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), s->txn->uri +

Re: stats webpage crash, htx and scope filter, [PATCH] REGTEST is included

2019-01-14 Thread Christopher Faulet

Le 12/01/2019 à 23:23, PiBa-NL a écrit :

Hi List,

I've configured haproxy with htx and when i try to filter the stats webpage.
Sending this request: "GET /?;csv;scope=b1" to '2.0-dev0-762475e
2019/01/10' it will crash with the trace below.
1.9.0 and 1.9.1 are also affected.

Can someone take a look? Thanks in advance.


Hi Pieter,

I'm on it. Thanks

--
Christopher Faulet



stats webpage crash, htx and scope filter, [PATCH] REGTEST is included

2019-01-12 Thread PiBa-NL

Hi List,

I've configured haproxy with htx and when i try to filter the stats webpage.
Sending this request: "GET /?;csv;scope=b1" to '2.0-dev0-762475e 
2019/01/10' it will crash with the trace below.

1.9.0 and 1.9.1 are also affected.

Can someone take a look? Thanks in advance.

A regtest is attached that reproduces the behavior, and which i think 
could be included into the haproxy repository.


Regards,
PiBa-NL (Pieter)

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00564fe7 in strnistr (str1=0x802631048 "fe1", len_str1=3, 
str2=0x804e3bf4c , 
len_str2=3)

    at src/standard.c:3657
3657    while (toupper(*start) != toupper(*str2)) {
(gdb) bt full
#0  0x00564fe7 in strnistr (str1=0x802631048 "fe1", len_str1=3, 
str2=0x804e3bf4c , 
len_str2=3)

    at src/standard.c:3657
    pptr = 0x804e3bf4c 0x804e3bf4c>

    sptr = 0x80271df80 "\330?"
    start = 0x802631048 "fe1"
    slen = 3
    plen = 3
    tmp1 = 0
    tmp2 = 4294959392
#1  0x004d01d3 in stats_dump_proxy_to_buffer (si=0x8026416d8, 
htx=0x8027c8e40, px=0x8026b3c00, uri=0x802638000) at src/stats.c:2079

    appctx = 0x802678380
    s = 0x802641400
    rep = 0x802641470
    sv = 0x8027c8e40
    svs = 0x33be1e0
    l = 0x4d31df 
    flags = 0
#2  0x004d4139 in stats_dump_stat_to_buffer (si=0x8026416d8, 
htx=0x8027c8e40, uri=0x802638000) at src/stats.c:2652

    appctx = 0x802678380
    rep = 0x802641470
    px = 0x8026b3c00
#3  0x004d56bb in htx_stats_io_handler (appctx=0x802678380) at 
src/stats.c:3299

    si = 0x8026416d8
    s = 0x802641400
    req = 0x802641410
    res = 0x802641470
    req_htx = 0x8027c8e40
    res_htx = 0x8027c8e40
#4  0x004d2546 in http_stats_io_handler (appctx=0x802678380) at 
src/stats.c:3367

    si = 0x8026416d8
    s = 0x802641400
    req = 0x802641410
    res = 0x802641470
#5  0x005f729f in task_run_applet (t=0x8026566e0, 
context=0x802678380, state=16385) at src/applet.c:85

    app = 0x802678380
    si = 0x8026416d8
#6  0x005f2533 in process_runnable_tasks () at src/task.c:435
    t = 0x8026566e0
    state = 16385
    ctx = 0x802678380
    process = 0x5f7200 
    t = 0x8026566e0
    max_processed = 199
#7  0x005163b2 in run_poll_loop () at src/haproxy.c:2619
    next = 0
    exp = 1137019023
#8  0x00513008 in run_thread_poll_loop (data=0x8026310f0) at 
src/haproxy.c:2684

    start_lock = 0
    ptif = 0x935d40 
    ptdf = 0x0
#9  0x0050f636 in main (argc=4, argv=0x7fffeb08) at 
src/haproxy.c:3313

    tids = 0x8026310f0
    threads = 0x8026310f8
    i = 1
    old_sig = {__bits = {0, 0, 0, 0}}
    blocked_sig = {__bits = {4227856759, 4294967295, 4294967295, 
4294967295}}

    err = 0
    retry = 200
    limit = {rlim_cur = 4052, rlim_max = 4052}
    errmsg = 
"\000\353\377\377\377\177\000\000\060\353\377\377\377\177\000\000\b\353\377\377\377\177\000\000\004\000\000\000\000\000\000\000t\240\220?\260|6\224`)\224\000\000\000\000\000\000\353\377\377\377\177\000\000\060\353\377\377\377\177\000\000\b\353\377\377\377\177\000\000\004\000\000\000\000\000\000\000\240\352\377\377\377\177\000\000R\201\000\002\b\000\000\000\001\000\000"

    pidfd = -1

From 838ecb4e153c1d859d0a49e0554ff050ff10033c Mon Sep 17 00:00:00 2001
From: PiBa-NL 
Date: Sat, 12 Jan 2019 21:57:48 +0100
Subject: [PATCH] REGTEST: checks basic stats webpage functionality

This regtest verifies that the stats webpage can be used to change a
server state to maintenance or drain, and that filtering the page scope
will result in a filtered page.
---
 .../h_webstats-scope-and-post-change.vtc  | 83 +++
 1 file changed, 83 insertions(+)
 create mode 100644 reg-tests/webstats/h_webstats-scope-and-post-change.vtc

diff --git a/reg-tests/webstats/h_webstats-scope-and-post-change.vtc 
b/reg-tests/webstats/h_webstats-scope-and-post-change.vtc
new file mode 100644
index ..a77483b5
--- /dev/null
+++ b/reg-tests/webstats/h_webstats-scope-and-post-change.vtc
@@ -0,0 +1,83 @@
+varnishtest "Webgui stats page check filtering with scope and changing server 
state"
+#REQUIRE_VERSION=1.6
+
+feature ignore_unknown_macro
+
+server s1 {
+} -start
+
+haproxy h1 -conf {
+  global
+stats socket /tmp/haproxy.socket level admin
+
+  defaults
+mode http
+${no-htx} option http-use-htx
+
+  frontend fe1
+bind "fd@${fe1}"
+stats enable
+stats refresh 5s
+stats uri /
+stats admin if TRUE
+
+  backend b1
+server srv1 ${s1_addr}:${s1_port}
+server srv2 ${s1_addr}:${s1_port}
+server srv3 ${s1_addr}:${s1_port}
+
+  backend b2
+server srv1 ${s1_addr}:${s1_port}
+server srv2 ${s1_addr}:${s1_port}
+
+} -start
+
+client c1 -connect ${h1_fe1_sock} {
+txreq -url "/;csv;"
+rxresp
+expect r