My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
regex.c
Go to the documentation of this file.
1 /*
2 START OF LICENSE STUB
3  DeDOS: Declarative Dispersion-Oriented Software
4  Copyright (C) 2017 University of Pennsylvania, Georgetown University
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 END OF LICENSE STUB
19 */
20 #include <string.h>
21 #include <stdio.h>
22 #include <pcre.h>
23 
24 #define EVIL_REGEX "^(a+)+$"
25 #define HTML "\
26 <!DOCTYPE html>\n\
27 <html>\n\
28  <body>\n\
29  <h1>Does %s match %s?</h1> <br/>\n\
30  <p>%s.</p>\n\
31  </body>\n\
32 </html>\
33 "
34 
35 int html_len(){
36  return strlen(HTML) + 200;
37 }
38 
39 int regex_html(char *to_match, char *htmlDoc){
40  const char *pcreErrorStr;
41  int errOffset;
42  pcre *reCompiled = pcre_compile(EVIL_REGEX, 0, &pcreErrorStr, &errOffset, NULL);
43 
44  pcre_extra pcreExtra;
45  pcreExtra.match_limit = -1;
46  pcreExtra.match_limit_recursion = -1;
47  pcreExtra.flags = PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION;
48 
49  int len = strlen(to_match);
50  int x[1];
51 
52  int ret = pcre_exec(reCompiled, &pcreExtra, to_match, len, 0, 0, x, 1);
53 
54  char resp[5];
55  if (ret < 0){
56  sprintf(resp, "%s", "NO");
57  } else {
58  sprintf(resp, "%s", "YES");
59  }
60  sprintf(htmlDoc, HTML, to_match, EVIL_REGEX, resp);
61  pcre_free(reCompiled);
62  return 0;
63 }
64 
65 
int regex_html(char *to_match, char *htmlDoc)
#define HTML
Definition: regex.c:25
#define EVIL_REGEX
Definition: regex.c:24
int html_len()
Definition: regex.c:35