From 9d73971cf55f356b59c70b444a4f85cc52c3e175 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Wed, 20 Jan 2016 09:26:31 +0800 Subject: [PATCH] test server http dont print junk if string too long Signed-off-by: Andy Green --- test-server/test-server-http.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test-server/test-server-http.c b/test-server/test-server-http.c index 2f4dd083d..f8cb1b503 100644 --- a/test-server/test-server-http.c +++ b/test-server/test-server-http.c @@ -62,7 +62,7 @@ struct serveable { void dump_handshake_info(struct lws *wsi) { - int n = 0; + int n = 0, len; char buf[256]; const unsigned char *c; @@ -73,12 +73,14 @@ dump_handshake_info(struct lws *wsi) continue; } - if (!lws_hdr_total_length(wsi, n)) { + len = lws_hdr_total_length(wsi, n); + if (!len || len > sizeof(buf) - 1) { n++; continue; } lws_hdr_copy(wsi, buf, sizeof buf, n); + buf[sizeof(buf) - 1] = '\0'; fprintf(stderr, " %s = %s\n", (char *)c, buf); n++;