-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Bug in safe_strtoull affecting use of incr and decr commands #1105
Comments
Thanks! I just fixed a similar bug in there recently. Will see what the deal is. |
(btw, great detail in the bug report here!) Looks like I don't have a lot of options, either:
Problem is only a performance consideration. I should be able to benchmark both approaches but it'll take a little more time. |
Sounds good, thank you. I also couldn't think of an elegant solution that solves the problem without potentially affecting the performance. The benchmarks will be interesting to see. |
I wrote a new tokenizer that I'll be switching to soon (I hope), which removes prefix spaces in the protocol. So at least for strto*'s in the protocol the memchr can be swapped with just checking for |
Just poking an update here. After some major delays due to some other projects running long... I'm on a path to getting this fixed again. In the new parser code I have custom strto*'s that are much more strict than the builtins: no spaces This should erase the class of failures where a missing null byte or junk data lets a strto wander off into memory. |
Describe the bug
There’s a bug in the util.c method safe_strtoull, that causes the commands “incr” and “decr” to work on negative item values.
This section in safe_strtoull:
causes the String that we gave to strtoull to be checked for the minus sign, but only if
(long long) ull < 0
Which works fine for any Strings with values between
-1
And
-9223372036854775808 = LONG_MIN
The problem with this is, with String with a value between:
-9223372036854775809 = LONG_MIN-1
And
-18446744073709551615
These will underflow into a positive value when typecast to (long long), causing the memchr check for the minus sign never to be done.
A value in this range is then accepted as safe and used in later methods
(as unsigned long long range values)
The part that leads directly to the error is that they’re use the proto_text.c method
process_arithmetic_command as well as the memcached.c method do_add_delta
This then leads to two kinds of reproducible error:
To Reproduce
One is that the “incr” delta itself can have this error:
The second (more likely to actually occur in use) is that the item content value can have this error:
System Information
Hardware Model: Dell Inspiron 5570
Memory: 8.0 GB
Processor: Intel Pentium(R) CPU 4415U @ 2.30GHz × 4
Graphics: Intel HD Graphics 610
Detail (please include!)
Always include the output of
stats
,stats settings
, and optionallystats items
andstats slabs
. These can be provided to a maintainer privately if necessary. Please sanitize anything secret from the data.The text was updated successfully, but these errors were encountered: