-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: integer type limits #3420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: integer type limits #3420
Conversation
…specific catch() blocks
…(SonarCloud issue)
|
Okay, I think I'm done with this. First: @jonathansmith9485, @SonNgo2211, @EsadCetiner - please take a review this. Please read the PR's description carefully, eg. if you set an out-of-bound value, then the engine will drop an error and won't start. If you could make a test, please try to decrease the limit and check the limit works as you expected too. Please note, that this PR fixes other similar issues too, eg. |
Hi @airween, |
Hi @SonNgo2211,
Thanks for bringing this up. Unfortunately that's a false information. I assume the author just copied the v2 documentation and left as is in v3. In v3 (libmodsecurity3) there isn't any hardcoded limit at all. I have to fix this in the mentioned documentation. |
@airween I just tested the PR and I'm still observing the same behavior, however unlike your previous PR, the directive is now overflowing instead of being set to 0
What values are considered out of bounds? I have |
Hmmm... sorry to ask, but are you sure you pulled down the correct branch and tested that code? I tried with your settings:
and send your original request:
Then I see only these lines in debug.log:
With the original code I got the same result as you.
The type of this variable is Could you build and run this C++ code on your machine? If yes, what do you get? // build: g++ ulonglimit.cpp -o ulonglimit
#include <limits>
#include <iostream>
int main() {
std::cout << std::numeric_limits<unsigned long>::max() << std::endl;
return 0;
} My result:
It's very-very weird that you get this message: |
I pulled this branch down I'm on a 64 bit system, so I'm not hitting the limit
That shouldn't be the case since I removed the old binaries installed via apt, I'll try compiling it in a completely fresh environment, play with it a bit there, then report back. |
cool,
okay, thanks,
Please note that if you use libmodsecurity3 through APT then the installed Nginx module looks the library under
If you don't set the path before you run Anyway, now I see I have to change the types, because on 32 bit systems the |
Thanks for that hint, I ran I set a stupidly large limit for |
no worries, it's a very good news that it works as well.
Cool. Meanwhile I realized that I (and the previous authors) used I'll ask a help again - thanks again. |
what
This PR fixes the handling of integer type limits, eg.
SecRequestBodyNoFilesLimit
.Changes:
headers/modsecurity/rules_set_properties.h
I implemented a new template with nameConfigValue
parse()
method which reads safely the integer value from a string, which parsed by engine's SecLang parser (Bison)min
andmax
value to0
ConfigInt
) implements signed integer, then the min and max limits will be -32767 and +32767 (INT_MIN
andINT_MAX
)ConfigInt
,ConfigUnsignedInt
andConfigUnsignedLong
std::numeric_limits<T>::min()
andstd::numeric_limits<T>::max()
m_argumentsLimit
,m_requestBodyJsonDepthLimit
,m_requestBodyLimit
,m_requestBodyNoFilesLimit
,m_responseBodyLimit
,m_pcreMatchLimit
,m_uploadFileLimit
andm_uploadFileMode
; the current types are here; now there is no moreConfigDouble
type variablesrc/parser/seclang-parser.yy
I changed the type in grammar parser; there you can see the error handling (detailed error messages are in template'sparse()
method)src/parser/seclang-parser.cc
(it's a generated file by Bison, don't need to check it)Other changes:
ConfigDouble
,ConfigString
andConfigSet
implementations (also inheaders/modsecurity/rules_set_properties.h
)headers/modsecurity/rules_set_properties.h
I had to add undefining macro directives if the target isWIN32
, because the CI workflow was unsuccessful on Windows, because - probably -min
andmax
are Windows C++ macroswhy
The problem with current solution is that the type of these variables are
ConfigDouble
, see the variable declarations and their type implementation.A quick review of current implementation:
atoi()
, which gives an integer with different bitsizeTherefore if a user gave an extra high value, then the
atoi()
converted it into a negative value.Previously I sent another PR (#3419), but I realized that solution wasn't complete. In this PR I reworked the whole storage implementation.
references
Fixes #3352 and #3356.