LCOV - code coverage report
Current view: top level - msus/webserver - regex.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 12 15 80.0 %
Date: 2018-01-11 Functions: 1 2 50.0 %

          Line data    Source code
       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           0 : int html_len(){
      36           0 :     return strlen(HTML) + 200;
      37             : }
      38             : 
      39           2 : int regex_html(char *to_match, char *htmlDoc){
      40             :     const char *pcreErrorStr;
      41             :     int errOffset;
      42           2 :     pcre *reCompiled = pcre_compile(EVIL_REGEX, 0, &pcreErrorStr, &errOffset, NULL);
      43             :     
      44             :     pcre_extra pcreExtra;
      45           2 :     pcreExtra.match_limit = -1;
      46           2 :     pcreExtra.match_limit_recursion = -1;
      47           2 :     pcreExtra.flags = PCRE_EXTRA_MATCH_LIMIT | PCRE_EXTRA_MATCH_LIMIT_RECURSION;
      48             :     
      49           2 :     int len = strlen(to_match);
      50             :     int x[1];
      51             : 
      52           2 :     int ret = pcre_exec(reCompiled, &pcreExtra, to_match, len, 0, 0, x, 1);
      53             :     
      54             :     char resp[5];
      55           2 :     if (ret < 0){
      56           2 :         sprintf(resp, "%s", "NO");
      57             :     } else {
      58           0 :         sprintf(resp, "%s", "YES");
      59             :     }
      60           2 :     sprintf(htmlDoc, HTML, to_match, EVIL_REGEX, resp);
      61           2 :     pcre_free(reCompiled);
      62           2 :     return 0;
      63             : }
      64             : 
      65             : 

Generated by: LCOV version 1.10