Skip to content

Commit

Permalink
Fix issue #674. Move regexp limits to limits.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed May 29, 2017
1 parent aa87174 commit 925bcf3
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 96 deletions.
20 changes: 20 additions & 0 deletions libyara/include/yara/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,24 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define LEX_BUF_SIZE 8192


// Maximum allowed split ID, also limiting the number of split instructions
// allowed in a regular expression. This number can't be increased
// over 255 without changing RE_SPLIT_ID_TYPE.
#define RE_MAX_SPLIT_ID 128

// Maximum stack size for regexp evaluation
#define RE_MAX_STACK 1024

// Maximum code size for a compiled regexp
#define RE_MAX_CODE_SIZE 32768

// Maximum input size scanned by yr_re_exec
#define RE_SCAN_LIMIT 4096

// Maximum number of fibers
#define RE_MAX_FIBERS 1024

// Maximum number of levels in regexp's AST
#define RE_MAX_AST_LEVELS 2000

#endif
1 change: 1 addition & 0 deletions libyara/include/yara/re.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ struct RE_NODE
struct RE_AST
{
uint32_t flags;
uint16_t levels;
RE_NODE* root_node;
};

Expand Down
18 changes: 1 addition & 17 deletions libyara/re.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,6 @@ order to avoid confusion with operating system threads.
#include <yara/re_lexer.h>
#include <yara/hex_lexer.h>

// Maximum allowed split ID, also limiting the number of split instructions
// allowed in a regular expression. This number can't be increased
// over 255 without changing RE_SPLIT_ID_TYPE.
#define RE_MAX_SPLIT_ID 128

// Maximum stack size for regexp evaluation
#define RE_MAX_STACK 1024

// Maximum code size for a compiled regexp
#define RE_MAX_CODE_SIZE 32768

// Maximum input size scanned by yr_re_exec
#define RE_SCAN_LIMIT 4096

// Maximum number of fibers
#define RE_MAX_FIBERS 1024


#define EMIT_BACKWARDS 0x01
#define EMIT_DONT_SET_FORWARDS_CODE 0x02
Expand Down Expand Up @@ -268,6 +251,7 @@ int yr_re_ast_create(
return ERROR_INSUFFICIENT_MEMORY;

(*re_ast)->flags = 0;
(*re_ast)->levels = 0;
(*re_ast)->root_node = NULL;

return ERROR_SUCCESS;
Expand Down
Loading

0 comments on commit 925bcf3

Please sign in to comment.