117 Commits

Author SHA1 Message Date
Joe Orton
de1cf63d26 Fix GCC warning in msc_headers_to_buffer():
In file included from /usr/include/stdio.h:970,
                 from modsecurity.h:18,
                 from msc_util.c:15:
In function 'sprintf',
    inlined from 'msc_headers_to_buffer' at msc_util.c:2331:17:
/usr/include/bits/stdio2.h:30:10: warning: '__sprintf_chk' argument 5 overlaps destination object 'buffer' [-Wrestrict]
   30 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   31 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   32 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~
msc_util.c: In function 'msc_headers_to_buffer':
msc_util.c:2306:64: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
 2306 | int msc_headers_to_buffer(const apr_array_header_t *arr, char *buffer,
      |                                                          ~~~~~~^~~~~~
2025-05-16 09:59:32 +01:00
Joe Orton
9d9a727349 Fix compiler warnings. Reported by GCC with flags:
-Wall -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS

Note, e.g. sprintf(digest, "%s%02x", digest, ...) is undefined behaviour because
the destination and source variables overlap, and GCC warnings for this.

acmp.c:258:13: warning: 'acmp_clone_node_no_state' defined but not used [-Wunused-function]
apache2_config.c:806:9: warning: unused variable 'offset' [-Wunused-variable]
apache2_config.c:1886:23: warning: unused variable 'dcfg' [-Wunused-variable]
apache2_config.c:1942:23: warning: unused variable 'dcfg' [-Wunused-variable]
apache2_config.c:2470:23: warning: unused variable 'dcfg' [-Wunused-variable]
apache2_config.c:2538:23: warning: unused variable 'dcfg' [-Wunused-variable]
apache2_util.c:226:11: warning: unused variable 'str' [-Wunused-variable]
apache2_util.c:225:11: warning: unused variable 'saved' [-Wunused-variable]
apache2_util.c:224:11: warning: unused variable 'parse_remote' [-Wunused-variable]
apache2_util.c:223:11: warning: unused variable 'remote' [-Wunused-variable]
msc_status_engine.c:216:17: warning: unused variable 'i' [-Wunused-variable]
msc_status_engine.c:375:55: warning: the address of 'pcre' will always evaluate as 'true' [-Waddress]
msc_crypt.c:67:17: warning: unused variable 'bytes' [-Wunused-variable]
msc_crypt.c:1083:33: warning: variable 'enc' set but not used [-Wunused-but-set-variable]
msc_crypt.c:1090:29: warning: variable 'enc' set but not used [-Wunused-but-set-variable]
/usr/include/bits/stdio2.h:30:10: warning: '__sprintf_chk' argument 5 overlaps destination object 'digest' [-Wrestrict]
msc_json.c:405:11: warning: unused variable 'json_data' [-Wunused-variable]
msc_crypt.c:1097:79: warning: '%s' directive argument is null [-Wformat-overflow=]
msc_logging.c:1144:20: warning: unused variable 'now' [-Wunused-variable]
msc_remote_rules.c:729:19: warning: unused variable 'word' [-Wunused-variable]
msc_remote_rules.c:727:17: warning: unused variable 'tmp' [-Wunused-variable]
msc_remote_rules.c:805:1: warning: control reaches end of non-void function [-Wreturn-type]
msc_tree.c:836:19: warning: unused variable 'ip' [-Wunused-variable]
msc_xml.c:29:44: warning: variable 'entity' set but not used [-Wunused-but-set-variable]
msc_util.c:2627:11: warning: unused variable 'start' [-Wunused-variable]
msc_util.c:2626:17: warning: unused variable 'fd' [-Wunused-variable]
msc_util.c:2624:18: warning: unused variable 'rc' [-Wunused-variable]
msc_util.c:1077:19: warning: array subscript 1 is outside array bounds of 'unsigned char[1]' [-Warray-bounds=]
2025-05-16 09:59:32 +01:00
Marc Stern
87dbae9bb2 assert(input != NULL); 2024-11-04 13:53:28 +01:00
Marc Stern
907d61ad6d Incorrect utf8toUnicode transformation for 00xx
Fix issue and restructure handling
2024-10-22 15:51:55 +02:00
Rainer Jung
149376377e Move id_log() to msc_util to fix unit tests; it is declared on msc_util.h already 2024-10-01 13:58:22 +02:00
Marc Stern
cd65a44d64 Removed useless code 2024-07-22 16:53:58 +02:00
Marc Stern
c8e1904da8 Missing function 2024-04-05 18:21:02 +02:00
Marc Stern
649aea7288
Merge branch 'v2/master' into v2/mst/nullcheck2 2024-04-04 16:08:59 +02:00
Marc Stern
91da5872c1 Many null pointer checks 2024-02-20 13:15:52 +01:00
Ervin Hegedus
3f8d21c4b1
Revert "Centralized function to get user name" 2024-02-07 23:08:06 +01:00
Marc Stern
0708339359 Centralized function to get user name, compatible with Linux & Windows (also with mpm-itk & mod_ruid2) 2023-08-11 17:22:24 +02:00
Marc Stern
b3b33c9ff1 Revert "Centralized function compatible with Linux & Windows (also with mpm-itk & mod_ruid2) to get username"
This reverts commit c7b28f0e13fa18d8503877e026744f76607cfbae.
2023-08-11 17:19:08 +02:00
Marc Stern
c7b28f0e13 Centralized function compatible with Linux & Windows (also with mpm-itk & mod_ruid2) to get username 2023-08-11 17:17:59 +02:00
Martin Vierula
8038a529c0
Copyright line updates 2022-12-21 07:07:14 -08:00
Martin Vierula
b5b4e2fdd1
Fix: negative usec on log line when data type long is 32b 2022-06-01 07:19:10 -07:00
Rainer Jung
f80114a906
Add microsec timestamp resolution to the formatted log timestamp. 2021-01-15 15:11:14 -03:00
Felipe Zimmerle
52532a1bce Fix curl callback function 2018-12-15 00:08:31 -03:00
Ervin Hegedus
0dcbb8b087
Fix inet addr handling on 64 bit big endian systems
Back port from v3. @zimmerle.
2018-12-10 15:39:58 -03:00
Victor Hora
b600669d02 Fix buffer size for utf8toUnicode transformation 2018-11-16 15:05:47 -03:00
Victor Hora
9be0a407eb Add sanity check for a couple malloc() and make code more resilient 2018-11-04 22:04:34 -05:00
Felipe Zimmerle
8dd40709ee
good practices: Initialize variables before use it
Original author: Marc Stern (#1889)
2018-09-05 23:35:52 -03:00
David Carlier
7ead7f4d23
Few missing headers, in the <arpa/inet.h> inclusions ones mainly due to the fact APR_HAVE* constants are simply into apr.h 2017-09-29 14:00:32 +00:00
Felipe Zimmerle
23823bb2c3 Makes Curl no longer a mandatory depedency for ModSecurity core
As reported by Rainer Jung, Curl may not be mandatory to build
	ModSecurity core. This patch make it optional by:
	- Concentrate all downloads using curl on msc_remote_rules.c
	- Split Curl build definitions checks into: WITH_CURL, WITH_REMOTE_RULES
	and WITH_CRYPTO.
	  - WITH_CURL: Contains Culr headers and binaries during the build time.
	  - WITH_REMOTE_RULES: Currently enabled if Curl is present.
	  - WITH_CRYPTO: Set if apr tool was compiled with crypto support.
	- Renames msc_remote_grab_content to msc_remote_download_content
2014-12-03 08:28:59 -08:00
Felipe Zimmerle
94fd570e31 Fix parser segfault on parser while parsing downloaded content
The error message was using a null pointer which was leading ModSecurity
to segfault
2014-11-21 03:52:03 -08:00
Felipe Zimmerle
9fe72b72de Improves the CA validation
On IIS CA validation was not working as libcurl on windows does not look for a
certificate store, unless it is specified. The resource downloads are now
respecting the SecRemoteRulesFailAction.
2014-11-17 19:32:32 -08:00
Felipe Zimmerle
b5398abaf2 Forces downloads using https-only for resources or rules
This commit makes ModSecurity to refuse to download or install rules
(SecRemoteRules) from sites that are not running HTTPS with a valid and
trusted certificate.
2014-11-14 11:53:40 -08:00
Felipe Zimmerle
9b836b652a Initial support to load rules from a remote server
New directive `SecRemoteRules' was added. It allows the user to load a
set of rules from a given HTTP server.
2014-11-14 11:53:40 -08:00
Felipe Zimmerle
899ee0c365 Adds support to load remote resources to pmFromFile and ipMatchFromFile
Initially those directives were only able to load content from a
local file. This commit extends this functionality allowing the user to
provide an HTTP URI that can be downloaded and loaded by ModSecurity.
Initially the download is associated with a server restart. For next
versions we expect to load such resources as it become outdated (Without
need to resetart the server).
2014-11-14 11:53:40 -08:00
Felipe Zimmerle
96865a92d3 Adds fuzzyHash operator
The fuzzyHash operator can be used to match files. In conjuntcion
with FILES_TMP_CONTENT collection it can scan uploaded files and
try to match it with a pre caculated list of know malicious content,
more details on how it works can be found on ssdeep website:
http://ssdeep.sourceforge.net/
2014-11-14 11:53:39 -08:00
Felipe Zimmerle
5d92e448ae Fixes subnets representations using slash notation
The ipv4 representation was only accepting slash notation with masks
represented in 2 digits. In the ipv6 implementation several fixies were made:
The maximum value to a bitmask was 64 which is not the reality, as ipv6 can
handle 128 bits. The second change was also to enable mask representation with
more and less than 2 digits. A more general fix was added to allow the unit
tests to work even if a invalid ip/range was informed during the creation of
the "tree", now it is checking if the tree is NULL while performing the
execution of the operator. Initial problem was reported at the issue: #706.
2014-06-11 09:31:53 -07:00
Felipe Zimmerle
0037a0732a Using RadixTree instead of list to storage IPs
Used by the operator @ipMatch and variants, this structure storage all the IPs
addresses for later comparison. Last version was using RadixTree only if the
set of IPs was specified from files. IPs specified as parameters, was using
a chained list. Chained lists may affect the performance, since lookups in
worst case will be O(n). RadixTrees could provide better results depending
on the amount of elements and its contents.
2014-03-31 16:22:10 -07:00
Felipe Zimmerle
80185e2a90 Bugfix: Missing ipv6 support check
The Function "ip_tree_from_file" was making a reference for
IPV6_TREE whitout checkingx if it was supported or not.
2014-03-31 16:22:10 -07:00
Felipe Zimmerle
b9fdc4fe3b Adds support to suspicious and whitelist to Read and Write limits
The operators @ipMatch, @ipMatchF and @ipMatchFromFile were
added to the functions: SecReadStateLimit and SecReadStateLimit,
by using them it is possible to declare a suspicious list. When
a suspicious list is given, the {Read|Write}StateLimit will be
applied just to the IPs that belongs to that restricted list.
Note that the negative of those operators (e.g. !@ipMatch) can be
used to place a whitelist. The {Read|Write}StateLimit
restrictions will not be applied to those in the whitelist.
This current version the Sec{Read|Write}StateLimit can be used
varios times to add elements to both lists, however, the
last informed limit will be applied for the entire group. This
feature is experimental, and suggestions on how to improve it
are very welcome. For further discussion use the issue: #353.
2014-03-31 16:22:10 -07:00
Felipe Zimmerle
28d4f9fce1 iis: Checks Win version before declare inet_pton
Checking for `!(NTDDI_VERSION >= NTDDI_VISTA)` to decide whenever or not
to declare the inet_pton function.
2014-03-31 16:22:10 -07:00
Felipe Zimmerle
bd0980f63d Reverts commit: a4202146b8d26b6615bbab986383fe0afae60d77
Testing inet_pton with the help of Steffen. Acording to Steffen we can use
!(NTDDI_VERSION >= NTDDI_VISTA) to identify that the specific Windows version
has this function defined or not, if so we can use the Windows version.
Reverting this commit to avoid to overwrite the Windows' function. And
see the original error that happened before this commit.
2014-03-31 16:22:10 -07:00
Felipe Zimmerle
d93ce9ceee Adds REQUEST_FULL and REQUEST_FULL_LENGTH variables
This variable is a combination from REQUEST_LINE, REQUEST_HEADERS and
REQUEST_BODY (if any). Expects for \n\n in between each of those values.
2014-03-31 07:14:55 -07:00
Greg Chow
5b0c933cf3 Fixes UTF8 to Unicode conversion bug in 4-byte encodings 2014-03-31 07:14:55 -07:00
Felipe \\\"Zimmerle\\\" Costa
a4202146b8 iis: Fix inet_pton build problem
There is a function named inet_pton on windows API, with different
signature. This patch just override the windows function and point
the inet_pton to our implementation.
2013-11-07 17:15:52 -02:00
Breno Silva
a6fd09b691 Fix null byte convertion into utf8toUnicode 2013-07-04 03:34:10 -07:00
Breno Silva
aa18ec7f45 Updated copyright dates 2013-04-19 03:20:46 -04:00
Greg Wroblewski
c53e743c86 IIS version improvements 2013-01-18 11:39:05 -08:00
Breno Silva
fc45a3fe3b Fixed compilation issue under Windows when APR ipv6 is disabled 2012-12-01 08:21:04 -04:00
Breno Silva
ce3cf00a2c Fixed byte conversion issue during logging under zlinux 2012-10-31 17:05:41 -04:00
brenosilva
eeb331ca46 Added utf8toUnicode tfn - fix typo 2012-08-24 17:04:52 +00:00
brenosilva
781a506bc9 Added utf8toUnicode tfn 2012-08-24 17:02:13 +00:00
brenosilva
7385b120a7 Fixed check if ip_strv is NULL 2012-08-16 12:52:38 +00:00
brenosilva
8cec8c7e6d Make internal m_strcasestr default 2012-08-15 16:08:02 +00:00
brenosilva
592ec392d1 Remove ctl:ruleUpdateTarget* and add ctl:ruleRemovetarget* 2012-08-02 18:04:53 +00:00
brenosilva
543a7db8a7 Check for strcasestr 2012-07-27 01:10:33 +00:00
brenosilva
81b74ba633 Fix code for windows 2012-06-16 19:33:22 +00:00