"Fossies" - the Fresh Open Source Software Archive

Member "openlitespeed-1.6.5/test/util/ahotest.cpp" (3 Jan 2020, 14892 Bytes) of package /linux/www/openlitespeed-1.6.5.src.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*****************************************************************************
    2 *    Open LiteSpeed is an open source HTTP server.                           *
    3 *    Copyright (C) 2013 - 2018  LiteSpeed Technologies, Inc.                 *
    4 *                                                                            *
    5 *    This program is free software: you can redistribute it and/or modify    *
    6 *    it under the terms of the GNU General Public License as published by    *
    7 *    the Free Software Foundation, either version 3 of the License, or       *
    8 *    (at your option) any later version.                                     *
    9 *                                                                            *
   10 *    This program is distributed in the hope that it will be useful,         *
   11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of          *
   12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
   13 *    GNU General Public License for more details.                            *
   14 *                                                                            *
   15 *    You should have received a copy of the GNU General Public License       *
   16 *    along with this program. If not, see http://www.gnu.org/licenses/.      *
   17 *****************************************************************************/
   18 #ifdef RUN_TEST
   19 
   20 #include <iostream>
   21 #include "ahotest.h"
   22 #include "unittest-cpp/UnitTest++.h"
   23 
   24 
   25 const char *inputErr[] =
   26 {
   27     "set-cookie",
   28     ".cookie",
   29     "expiressys.user_objects",
   30     "sys.user_triggers",
   31     "@@spid",
   32     "msysaces",
   33     "instr",
   34     "sys.user_views",
   35     "mysql.",
   36     "sys.tab",
   37     "charindex",
   38     "locate",
   39     "sys.user_catalog",
   40     "constraint_type",
   41     "msysobjects",
   42     "attnotnull",
   43     "select",
   44     "sys.user_tables",
   45     "sys.user_constraints",
   46     "sys.user_tab_columns",
   47     "waitfor",
   48     "sys.all_tables",
   49     "msysrelationships",
   50     "msyscolumns",
   51     "msysqueriessubstr",
   52     "xtype",
   53     "textpos",
   54     "all_objects",
   55     "rownum",
   56     "sysfilegroups",
   57     "sysprocesses",
   58     "user_group",
   59     "sysobjects",
   60     "systables",
   61     "user_tables",
   62     "pg_attribute",
   63     "column_id",
   64     "user_password",
   65     "user_users",
   66     "attrelid",
   67     "user_tab_columns",
   68     "table_name",
   69     "pg_class",
   70     "user_constraints",
   71     "user_objects",
   72     "object_type",
   73     "sysconstraints",
   74     "mb_users",
   75     "column_name",
   76     "atttypid",
   77     "substring",
   78     "object_id",
   79     "syscat",
   80     "sysibm",
   81     "user_ind_columns",
   82     "syscolumns",
   83     "sysdba",
   84     "object_name",
   85     "sqrt",
   86     "insert",
   87     "date",
   88     "instr",
   89     "floor",
   90     "autonomous_transaction",
   91     "print",
   92     "encode",
   93     "coalesce",
   94     "if",
   95     "degrees",
   96     "release_lock",
   97     "procedure_analyse",
   98     "password",
   99     "least",
  100     "cr32",
  101     "subdate",
  102     "xp_filelist",
  103     "owa_util",
  104     "trim",
  105     "xp_regenumkeys",
  106     "charset",
  107     "ciel",
  108     "bit_or",
  109     "delete",
  110     "time",
  111     "month",
  112     "xp_execresultset",
  113     "round",
  114     "dba_users",
  115     "is",
  116     "master_pos_wait",
  117     "decode",
  118     "unhex",
  119     "char_length",
  120     "strcmp",
  121     "rtrim",
  122     "'sa'",
  123     "version",
  124     "ord",
  125     "xp_makecab",
  126     "truncate",
  127     "last",
  128     "concat",
  129     "coercibility",
  130     "right",
  131     "length",
  132     "ascii",
  133     "var_samp",
  134     "char",
  135     "extract",
  136     "get_",
  137     "bit_length",
  138     "xp_regread",
  139     "export_set",
  140     "aes_decrypt",
  141     "name_const",
  142     "left",
  143     "conv",
  144     "bin",
  145     "not_in",
  146     "infile",
  147     "substr",
  148     "uuid",
  149     "is_srvrolemember",
  150     "var_pop",
  151     "ln",
  152     "aes_encrypt",
  153     "outfile",
  154     "current_date",
  155     "quote",
  156     "in",
  157     "user",
  158     "locate",
  159     "@@version",
  160     "exp",
  161     "current_timestamp",
  162     "sql_longvarchar",
  163     "values",
  164     "subtime",
  165     "xp_loginconfig",
  166     "sin",
  167     "xp_regaddmultistring",
  168     "replace",
  169     "tan",
  170     "xmltype",
  171     "character_length",
  172     "cast",
  173     "current_time",
  174     "varchar",
  175     "position",
  176     "to_number",
  177     "addtime",
  178     "mid",
  179     "found_rows",
  180     "stddev",
  181     "xp_availablemedia",
  182     "substring",
  183     "dumpfile",
  184     "isnull",
  185     "cot",
  186     "select",
  187     "concat_ws",
  188     "convert",
  189     "uncompress",
  190     "radians",
  191     "uncompressed_length",
  192     "acos",
  193     "'sqloledb'",
  194     "dbms_pipe.receive_message",
  195     "utl_http",
  196     "cieling",
  197     "row_count",
  198     "benchmark",
  199     "sec_to_time",
  200     "sysdate",
  201     "hour",
  202     "current_user",
  203     "utc_",
  204     "curdate",
  205     "nvarchar",
  206     "schema",
  207     "data_type",
  208     "lcase",
  209     "inner",
  210     "make_set",
  211     "day",
  212     "tbcreator",
  213     "sum",
  214     "sign",
  215     "adddate",
  216     "ltrim",
  217     "variance",
  218     "weight_string",
  219     "second",
  220     "microsecond",
  221     "system_user",
  222     "abs",
  223     "ifnull",
  224     "minute",
  225     "unix_timestamp",
  226     "collation",
  227     "curtime",
  228     "lower",
  229     "repeat",
  230     "sp_oacreate",
  231     "group_concat",
  232     "sp_execute",
  233     "xp_ntsec",
  234     "xp_regdeletekey",
  235     "drop",
  236     "quarter",
  237     "local",
  238     "str_to_date",
  239     "nullif",
  240     "from_",
  241     "old_password",
  242     "xp_regdeletevalue",
  243     "asin",
  244     "oct",
  245     "load_file",
  246     "sp_password",
  247     "bit_xor",
  248     "xp_regremovemultistring",
  249     "chr",
  250     "avg",
  251     "std",
  252     "openquery",
  253     "makedate",
  254     "database",
  255     "updatexml",
  256     "datediff",
  257     "now",
  258     "year",
  259     "mod",
  260     "bit_and",
  261     "lpad",
  262     "xp_enumdsn",
  263     "max",
  264     "period_",
  265     "soundex",
  266     "shutdown",
  267     "bit_count",
  268     "field",
  269     "connection_id",
  270     "sha",
  271     "default",
  272     "interval",
  273     "xp_dirtree",
  274     "reverse",
  275     "ucase",
  276     "compress",
  277     "xp_terminate_process",
  278     "md5",
  279     "rpad",
  280     "session_user",
  281     "find_in_set",
  282     "dump",
  283     "convert_tz",
  284     "having",
  285     "des_",
  286     "greatest",
  287     "xp_regenumvalues",
  288     "utl_file",
  289     "cos",
  290     "log",
  291     "pi",
  292     "sql_variant",
  293     "encrypt",
  294     "upper",
  295     "rand",
  296     "week",
  297     "min",
  298     "xp_cmdshell",
  299     "'msdasql'",
  300     "space",
  301     "sp_executesql",
  302     "elt",
  303     "pow",
  304     "'dbo'",
  305     "sp_makewebtask",
  306     "dbms_java",
  307     "to_",
  308     "format",
  309     "xp_regwrite",
  310     "sp_helpjscript",
  311     "onsubmit",
  312     "copyparentfolder",
  313     "document",
  314     "javascript",
  315     "meta",
  316     "onchange",
  317     "onmove",
  318     "onkeydown",
  319     "onkeyup",
  320     "activexobject",
  321     "onerror",
  322     "onmouseup",
  323     "ecmascript",
  324     "bexpression",
  325     "onmouseover",
  326     "vbscript:",
  327     "<![cdata[",
  328     "http:",
  329     ".innerhtml",
  330     "settimeout",
  331     "shell:",
  332     "onabort",
  333     "asfunction:",
  334     "onkeypress",
  335     "onmousedown",
  336     "onclick",
  337     ".fromcharcode",
  338     "background-image:",
  339     "x-javascript",
  340     "ondragdrop",
  341     "onblur",
  342     "mocha:",
  343     "javascript:",
  344     "onfocus",
  345     "lowsrc",
  346     "getparentfolder",
  347     "onresize",
  348     "@import",
  349     "alert",
  350     "script",
  351     "onselect",
  352     "onmouseout",
  353     "application",
  354     "onmousemove",
  355     "background",
  356     ".execscript",
  357     "livescript:",
  358     "vbscript",
  359     "getspecialfolder",
  360     ".addimport",
  361     "iframe",
  362     "onunload",
  363     "createtextrange",
  364     "<input",
  365     "onload.www_acl",
  366     ".htpasswd",
  367     ".htaccess",
  368     "httpd.conf",
  369     "boot.ini",
  370     "/etc/",
  371     ".htgroup",
  372     "global.asa",
  373     ".wwwaclnet.exe",
  374     "cmd.exe",
  375     "cmd",
  376     "telnet.exe",
  377     "wguest.exe",
  378     "ftp.exe",
  379     "nmap.exe",
  380     "wsh.exe",
  381     "rcmd.exe",
  382     "nc.exe",
  383     "cmd32.exechgrp",
  384     "cmd32",
  385     "uname",
  386     "kill",
  387     "localgroup",
  388     "wguest.exe",
  389     "nasm",
  390     "rcmd.exe",
  391     "nc.exe",
  392     "id",
  393     "nc",
  394     "tclsh",
  395     "finger",
  396     "tftp",
  397     "cmd",
  398     "chown",
  399     "chsh",
  400     "ping",
  401     "nmap.exe",
  402     "ps",
  403     "net.exe",
  404     "telnet.exe",
  405     "ls",
  406     "tclsh8",
  407     "ftp.exe",
  408     "ftp",
  409     "lsof",
  410     "xterm",
  411     "mail",
  412     "echo",
  413     "tracert",
  414     "nmap",
  415     "cmd.exe",
  416     "rm",
  417     "python",
  418     "cd",
  419     "traceroute",
  420     "chmod",
  421     "perl",
  422     "passwd",
  423     "wsh.exe",
  424     "cpp",
  425     "telnet",
  426     "gcc",
  427     "g++chgrp",
  428     "cmd32",
  429     "uname",
  430     "kill",
  431     "localgroup",
  432     "wguest.exe",
  433     "nasm",
  434     "rcmd.exe",
  435     "nc.exe",
  436     "id",
  437     "nc",
  438     "tclsh",
  439     "finger",
  440     "tftp",
  441     "cmd",
  442     "chown",
  443     "chsh",
  444     "ping",
  445     "nmap.exe",
  446     "ps",
  447     "net.exe",
  448     "telnet.exe",
  449     "ls",
  450     "tclsh8",
  451     "ftp.exe",
  452     "ftp",
  453     "lsof",
  454     "xterm",
  455     "mail",
  456     "echo",
  457     "tracert",
  458     "nmap",
  459     "cmd.exe",
  460     "rm",
  461     "python",
  462     "cd",
  463     "traceroute",
  464     "chmod",
  465     "perl",
  466     "passwd",
  467     "wsh.exe",
  468     "cpp",
  469     "telnet",
  470     "gcc",
  471     "g++<?"
  472 };
  473 
  474 static void checkErr()
  475 {
  476     int count = 445;
  477     int i;
  478     size_t iOutStart = 0, iOutEnd = 0;
  479     ls_aho_state_t **outlast = (ls_aho_state_t **)malloc(sizeof(
  480                                    ls_aho_state_t **));
  481 //     Aho *ac = new Aho( 1 );
  482     ls_aho_t *ac = ls_aho_new(1);
  483     for (i = 0; i < count; ++i)
  484     {
  485         if ((ls_aho_addpattern(ac, inputErr[i], strlen(inputErr[i]), NULL) == 0))
  486 //         if ((ac->addPattern( inputErr[i], strlen( inputErr[i] ) )) == 0 )
  487         {
  488             std::cout << "Add patterns failed." << std::endl;
  489             ls_aho_delete(ac);
  490             return;
  491         }
  492     }
  493     if (ls_aho_maketree(ac, 1) == 0)
  494     {
  495         std::cout << "Make tree failed." << std::endl;
  496         ls_aho_delete(ac);
  497         return;
  498     }
  499 
  500     ls_aho_search(ac, NULL, "_wpnonce", 8, 0, &iOutStart, &iOutEnd, outlast, NULL);
  501     ls_aho_delete(ac);
  502     return;
  503 }
  504 
  505 TEST(AhoTest)
  506 {
  507     checkErr();
  508 //     int iNumTests = 8;
  509 //     size_t iOutStart = 0, iOutEnd = 0;
  510 //     Aho *ac;
  511 //     AhoState **outlast = (AhoState **)malloc( sizeof( AhoState ** ) );
  512 //
  513 //     std::cout << "Start Aho Test" << std::endl;
  514 //
  515 //     for( int i = 0; i < iNumTests; ++i )
  516 //     {
  517 //         ac = getTree(aTestAccept[i], aTestAcceptLen[i], aSensitive[i]);
  518 //         if (ac == NULL)
  519 //         {
  520 //             std::cout << "Get Tree failed." << std::endl;
  521 //             return;
  522 //         }
  523 //
  524 //         ac->search( NULL, aTestInput[i], aTestInputLen[i], 0, &iOutStart, &iOutEnd, outlast );
  525 //
  526 //         CHECK( iOutStart == aOutStartRes[i] && iOutEnd == aOutEndRes[i] );
  527 //         iOutStart = 0;
  528 //         iOutEnd = 0;
  529 //         delete ac;
  530 //     }
  531 //     free( outlast );
  532 }
  533 
  534 Aho *getTree(const char *acceptBuf[], int bufCount, int sensitive)
  535 {
  536     int i;
  537     Aho *ac = new Aho(sensitive);
  538 
  539     for (i = 0; i < bufCount; ++i)
  540     {
  541         if ((ac->addPattern(acceptBuf[i], strlen(acceptBuf[i]), NULL)) == 0)
  542         {
  543             std::cout << "Add patterns failed." << std::endl;
  544             delete(ac);
  545             return NULL;
  546         }
  547     }
  548 
  549     if (ac->makeTree() == 0)
  550     {
  551         std::cout << "Make tree failed." << std::endl;
  552         delete(ac);
  553         return NULL;
  554     }
  555 
  556     if (ac->optimizeTree() == 0)
  557     {
  558         std::cout << "Optimize failed." << std::endl;
  559         delete(ac);
  560         return NULL;
  561     }
  562 
  563     return ac;
  564 }
  565 
  566 //input data causes problem
  567 /*
  568 set-cookie
  569 .cookie
  570 expiressys.user_objects
  571 sys.user_triggers
  572 @@spid
  573 msysaces
  574 instr
  575 sys.user_views
  576 mysql.
  577 sys.tab
  578 charindex
  579 locate
  580 sys.user_catalog
  581 constraint_type
  582 msysobjects
  583 attnotnull
  584 select
  585 sys.user_tables
  586 sys.user_constraints
  587 sys.user_tab_columns
  588 waitfor
  589 sys.all_tables
  590 msysrelationships
  591 msyscolumns
  592 msysqueriessubstr
  593 xtype
  594 textpos
  595 all_objects
  596 rownum
  597 sysfilegroups
  598 sysprocesses
  599 user_group
  600 sysobjects
  601 systables
  602 user_tables
  603 pg_attribute
  604 column_id
  605 user_password
  606 user_users
  607 attrelid
  608 user_tab_columns
  609 table_name
  610 pg_class
  611 user_constraints
  612 user_objects
  613 object_type
  614 sysconstraints
  615 mb_users
  616 column_name
  617 atttypid
  618 substring
  619 object_id
  620 syscat
  621 sysibm
  622 user_ind_columns
  623 syscolumns
  624 sysdba
  625 object_name
  626 sqrt
  627 insert
  628 date
  629 instr
  630 floor
  631 autonomous_transaction
  632 print
  633 encode
  634 coalesce
  635 if
  636 degrees
  637 release_lock
  638 procedure_analyse
  639 password
  640 least
  641 cr32
  642 subdate
  643 xp_filelist
  644 owa_util
  645 trim
  646 xp_regenumkeys
  647 charset
  648 ciel
  649 bit_or
  650 delete
  651 time
  652 month
  653 xp_execresultset
  654 round
  655 dba_users
  656 is
  657 master_pos_wait
  658 decode
  659 unhex
  660 char_length
  661 strcmp
  662 rtrim
  663 'sa'
  664 version
  665 ord
  666 xp_makecab
  667 truncate
  668 last
  669 concat
  670 coercibility
  671 right
  672 length
  673 ascii
  674 var_samp
  675 char
  676 extract
  677 get_
  678 bit_length
  679 xp_regread
  680 export_set
  681 aes_decrypt
  682 name_const
  683 left
  684 conv
  685 bin
  686 not_in
  687 infile
  688 substr
  689 uuid
  690 is_srvrolemember
  691 var_pop
  692 ln
  693 aes_encrypt
  694 outfile
  695 current_date
  696 quote
  697 in
  698 user
  699 locate
  700 @@version
  701 exp
  702 current_timestamp
  703 sql_longvarchar
  704 values
  705 subtime
  706 xp_loginconfig
  707 sin
  708 xp_regaddmultistring
  709 replace
  710 tan
  711 xmltype
  712 character_length
  713 cast
  714 current_time
  715 varchar
  716 position
  717 to_number
  718 addtime
  719 mid
  720 found_rows
  721 stddev
  722 xp_availablemedia
  723 substring
  724 dumpfile
  725 isnull
  726 cot
  727 select
  728 concat_ws
  729 convert
  730 uncompress
  731 radians
  732 uncompressed_length
  733 acos
  734 'sqloledb'
  735 dbms_pipe.receive_message
  736 utl_http
  737 cieling
  738 row_count
  739 benchmark
  740 sec_to_time
  741 sysdate
  742 hour
  743 current_user
  744 utc_
  745 curdate
  746 nvarchar
  747 schema
  748 data_type
  749 lcase
  750 inner
  751 make_set
  752 day
  753 tbcreator
  754 sum
  755 sign
  756 adddate
  757 ltrim
  758 variance
  759 weight_string
  760 second
  761 microsecond
  762 system_user
  763 abs
  764 ifnull
  765 minute
  766 unix_timestamp
  767 collation
  768 curtime
  769 lower
  770 repeat
  771 sp_oacreate
  772 group_concat
  773 sp_execute
  774 xp_ntsec
  775 xp_regdeletekey
  776 drop
  777 quarter
  778 local
  779 str_to_date
  780 nullif
  781 from_
  782 old_password
  783 xp_regdeletevalue
  784 asin
  785 oct
  786 load_file
  787 sp_password
  788 bit_xor
  789 xp_regremovemultistring
  790 chr
  791 avg
  792 std
  793 openquery
  794 makedate
  795 database
  796 updatexml
  797 datediff
  798 now
  799 year
  800 mod
  801 bit_and
  802 lpad
  803 xp_enumdsn
  804 max
  805 period_
  806 soundex
  807 shutdown
  808 bit_count
  809 field
  810 connection_id
  811 sha
  812 default
  813 interval
  814 xp_dirtree
  815 reverse
  816 ucase
  817 compress
  818 xp_terminate_process
  819 md5
  820 rpad
  821 session_user
  822 find_in_set
  823 dump
  824 convert_tz
  825 having
  826 des_
  827 greatest
  828 xp_regenumvalues
  829 utl_file
  830 cos
  831 log
  832 pi
  833 sql_variant
  834 encrypt
  835 upper
  836 rand
  837 week
  838 min
  839 xp_cmdshell
  840 'msdasql'
  841 space
  842 sp_executesql
  843 elt
  844 pow
  845 'dbo'
  846 sp_makewebtask
  847 dbms_java
  848 to_
  849 format
  850 xp_regwrite
  851 sp_helpjscript
  852 onsubmit
  853 copyparentfolder
  854 document
  855 javascript
  856 meta
  857 onchange
  858 onmove
  859 onkeydown
  860 onkeyup
  861 activexobject
  862 onerror
  863 onmouseup
  864 ecmascript
  865 bexpression
  866 onmouseover
  867 vbscript:
  868 <![cdata[
  869 http:
  870 .innerhtml
  871 settimeout
  872 shell:
  873 onabort
  874 asfunction:
  875 onkeypress
  876 onmousedown
  877 onclick
  878 .fromcharcode
  879 background-image:
  880 x-javascript
  881 ondragdrop
  882 onblur
  883 mocha:
  884 javascript:
  885 onfocus
  886 lowsrc
  887 getparentfolder
  888 onresize
  889 @import
  890 alert
  891 script
  892 onselect
  893 onmouseout
  894 application
  895 onmousemove
  896 background
  897 .execscript
  898 livescript:
  899 vbscript
  900 getspecialfolder
  901 .addimport
  902 iframe
  903 onunload
  904 createtextrange
  905 <input
  906 onload.www_acl
  907 .htpasswd
  908 .htaccess
  909 httpd.conf
  910 boot.ini
  911 /etc/
  912 .htgroup
  913 global.asa
  914 .wwwaclnet.exe
  915 cmd.exe
  916 cmd
  917 telnet.exe
  918 wguest.exe
  919 ftp.exe
  920 nmap.exe
  921 wsh.exe
  922 rcmd.exe
  923 nc.exe
  924 cmd32.exechgrp
  925 cmd32
  926 uname
  927 kill
  928 localgroup
  929 wguest.exe
  930 nasm
  931 rcmd.exe
  932 nc.exe
  933 id
  934 nc
  935 tclsh
  936 finger
  937 tftp
  938 cmd
  939 chown
  940 chsh
  941 ping
  942 nmap.exe
  943 ps
  944 net.exe
  945 telnet.exe
  946 ls
  947 tclsh8
  948 ftp.exe
  949 ftp
  950 lsof
  951 xterm
  952 mail
  953 echo
  954 tracert
  955 nmap
  956 cmd.exe
  957 rm
  958 python
  959 cd
  960 traceroute
  961 chmod
  962 perl
  963 passwd
  964 wsh.exe
  965 cpp
  966 telnet
  967 gcc
  968 g++chgrp
  969 cmd32
  970 uname
  971 kill
  972 localgroup
  973 wguest.exe
  974 nasm
  975 rcmd.exe
  976 nc.exe
  977 id
  978 nc
  979 tclsh
  980 finger
  981 tftp
  982 cmd
  983 chown
  984 chsh
  985 ping
  986 nmap.exe
  987 ps
  988 net.exe
  989 telnet.exe
  990 ls
  991 tclsh8
  992 ftp.exe
  993 ftp
  994 lsof
  995 xterm
  996 mail
  997 echo
  998 tracert
  999 nmap
 1000 cmd.exe
 1001 rm
 1002 python
 1003 cd
 1004 traceroute
 1005 chmod
 1006 perl
 1007 passwd
 1008 wsh.exe
 1009 cpp
 1010 telnet
 1011 gcc
 1012 g++<?
 1013 */
 1014 //search string "_wpnonce" should causes crash.
 1015 
 1016 
 1017 #endif
 1018 
 1019