From 4eeb1c093d30f887633a8e727b5daaa1de6b8150 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 8 Sep 2017 01:55:18 -0700 Subject: [PATCH] ircd::http: Proper exception when parse buffer is too small. --- include/ircd/parse.h | 1 + ircd/http.cc | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/ircd/parse.h b/include/ircd/parse.h index e444d37b6..d70a20ae6 100644 --- a/include/ircd/parse.h +++ b/include/ircd/parse.h @@ -35,6 +35,7 @@ struct ircd::parse IRCD_EXCEPTION(ircd::error, error) IRCD_EXCEPTION(error, grammar_error) IRCD_EXCEPTION(error, syntax_error) + IRCD_EXCEPTION(error, buffer_error) using read_closure = std::function; using parse_closure = std::function; diff --git a/ircd/http.cc b/ircd/http.cc index 3a2c6da91..05be263fb 100644 --- a/ircd/http.cc +++ b/ircd/http.cc @@ -490,12 +490,16 @@ ircd::http::content::content(parse::capstan &pc, pc.parsed = pc.read; } - assert(pc.parsed == base + length); - assert(pc.parsed == pc.read); + //assert(pc.parsed == base + length); + if(unlikely(pc.parsed < base + length)) + throw parse::buffer_error("parse buffer short by %zu to hold %zu total bytes of content", + remain, + length); if(pc.remaining()) *pc.read = '\0'; + assert(pc.parsed == pc.read); return string_view { base, pc.parsed }; }()} {