From: helly Date: Mon, 3 Mar 2008 23:23:22 +0000 (+0000) Subject: - Add overflow tests (we allow 8K max input right now) X-Git-Tag: 0.13.6~79 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e755698d21bc508e3a2575aa368b454dd83faca;p=re2c - Add overflow tests (we allow 8K max input right now) --- diff --git a/re2c/bootstrap/scanner.cc b/re2c/bootstrap/scanner.cc index d481b240..c546ab92 100644 --- a/re2c/bootstrap/scanner.cc +++ b/re2c/bootstrap/scanner.cc @@ -1,4 +1,4 @@ -/* Generated by re2c 0.13.3.dev on Sun Mar 2 21:34:25 2008 */ +/* Generated by re2c 0.13.3.dev on Tue Mar 4 00:16:12 2008 */ /* $Id$ */ #include #include @@ -1746,6 +1746,14 @@ Scanner::~Scanner() } } +void Scanner::check_token_length(uint len) const +{ + if (len >= BSIZE) + { + fatal("Token exceeds limit"); + } +} + SubStr Scanner::raw_token(std::string enclosure) const { return SubStr(std::string(enclosure + token().to_string() + enclosure).c_str()); diff --git a/re2c/scanner.h b/re2c/scanner.h index bcfda39b..4aa3bb53 100644 --- a/re2c/scanner.h +++ b/re2c/scanner.h @@ -39,6 +39,7 @@ public: void config(const Str&, int); void config(const Str&, const Str&); + void check_token_length(uint len) const; SubStr token() const; SubStr token(uint start, uint len) const; SubStr raw_token(std::string enclosure) const; @@ -65,11 +66,13 @@ inline void Scanner::fatal(const char *msg) const inline SubStr Scanner::token() const { + check_token_length(cur - tok); return SubStr(tok, cur - tok); } inline SubStr Scanner::token(uint start, uint len) const { + check_token_length(len); return SubStr(tok + start, len); } diff --git a/re2c/scanner.re b/re2c/scanner.re index a19113da..5261e699 100644 --- a/re2c/scanner.re +++ b/re2c/scanner.re @@ -626,6 +626,14 @@ Scanner::~Scanner() } } +void Scanner::check_token_length(uint len) const +{ + if (len >= BSIZE) + { + fatal("Token exceeds limit"); + } +} + SubStr Scanner::raw_token(std::string enclosure) const { return SubStr(std::string(enclosure + token().to_string() + enclosure).c_str());