Skip to content

config memory limits: handle values larger than (signed) LLONG_MAX#9313

Merged
oranagra merged 29 commits intoredis:unstablefrom
hwware:issue_9071_maxmemory
Aug 23, 2021
Merged

config memory limits: handle values larger than (signed) LLONG_MAX#9313
oranagra merged 29 commits intoredis:unstablefrom
hwware:issue_9071_maxmemory

Conversation

@hwware
Copy link
Contributor

@hwware hwware commented Aug 3, 2021

This PR is for #9071.

This aims to solve the issue in CONFIG SET maxmemory can only set maxmemory to up to 9223372036854775807 (2^63) while the maxmemory should be ULLONG. Added a memtoull function to convert a string representing an amount of memory into the number of bytes (similar to memtoll but for ull). Also added ull2string to convert a ULLong to string (Similar to ll2string).

@madolson
Copy link
Contributor

madolson commented Aug 4, 2021

Do we actually think this is worth implementing? This seems like a lot of effort to solve a problem that doesn't really matter. Thoughts?

@oranagra
Copy link
Member

oranagra commented Aug 5, 2021

i agree this is not a real problem, and if we solve it is only in order to have a cleaner code.
in this case cleaner code is one that doesn't have unexpected truncation, but i'm not sure it worth it.
maybe changing the high limit of this config (and others) to LLONG_MAX rather than ULLONG_MAX is enough?

@madolson
Copy link
Contributor

madolson commented Aug 7, 2021

I agree with changing the upper limit to LLONG_MAX.

@Super-long
Copy link
Contributor

I think this is not meaningful in terms of the problem to be solved. But I think it’s not a bad thing to provide the ability to configure ull, maybe it’s better to modify it when really needed.

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hwware i looked at it again.
I agree it would be nice to solve the problem and have cleaner code with no unexpected truncation, but i really don't like the code duplication (code is not cleaner this way!).

I think there's a good chance you can do better.

one example is that ull2string and ll2string can probably be unified in some way, maybe by putting most logic in ull2string and have ll2string call it and to the pre/post fixups.

regarding memtoull and memtoll there's probably no need for both, memory configs are always 0 (maybe with the exception of what i'm attempting in #7911).

I also imagine that the big if-else blocks with 90% common code you added in numericConfigSet and numericConfigGet can in some way be written to share code.

@hwware
Copy link
Contributor Author

hwware commented Aug 9, 2021

Ok got it. Thanks for the review, I will refactor and adjust the code.

@hwware hwware marked this pull request as draft August 11, 2021 21:42
@oranagra oranagra changed the title Issue 9071 maxmemory config memory limits: handle values larger than (signed) LLONG_MAX Aug 12, 2021
@oranagra
Copy link
Member

looks good. (cleaner than the initial version).
i still think the negative argument needs to be removed from ull2string.
after that i'm good to merge this.

@hwware
Copy link
Contributor Author

hwware commented Aug 20, 2021

@oranagra , I pushed the changes addressing the negative argument. Please take a look. Thanks

@oranagra
Copy link
Member

@hwware please look at my edit to see what i meant.
now ull2string doesn't need to have anything to do with negative numbers (it's all handled in ll2string)
it came out a bit more complicated that i thought it would since i also handled error case of insufficient buffer size.
also moved the comment about the algorithm to the right place.
please let me know if you see any problems.

@hwware
Copy link
Contributor Author

hwware commented Aug 20, 2021

@oranagra yes this looks fine to me too.

@oranagra
Copy link
Member

@hwware please take a look at my changes.
it fixes config set to use the right variable type (unsigned long long), but also change the timeout validation to use the right parsing function).
i suppose this makes it a breaking change (in case someone used 10k for timeout instead of using 10000. although i think that person would have got a timeout of 10, right?

@enjoy-binbin
Copy link
Contributor

The last change is a bit similar to this one #9308

@oranagra
Copy link
Member

@enjoy-binbin right, i had to do part of it because of the variable was the wrong type and there was a negative check, and then i noticed that the timeout was verified with the wrong method.
anyway, your PR goes deeper (validation of config file parsing), and will need to be rebased anyway after this one is merged, so let's do that after.

@oranagra oranagra added the state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten label Aug 22, 2021
@hwware
Copy link
Contributor Author

hwware commented Aug 23, 2021

@oranagra I think the changes are good. And yes you are right, in the case the use specifies 10k as timeout instead of 10000 then the timeout will be set to 10.

@oranagra oranagra merged commit 641780a into redis:unstable Aug 23, 2021
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Aug 24, 2021
This one follow redis#9313 and goes deeper (validation of config file parsing)

Move the check/update logic to a new updateClientOutputBufferLimit
function. So that it can be used in CONFIG SET and config file parsing.
oranagra pushed a commit that referenced this pull request Aug 29, 2021
This one follow #9313 and goes deeper (validation of config file parsing)

Move the check/update logic to a new updateClientOutputBufferLimit
function. So that it can be used in CONFIG SET and config file parsing.
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Sep 8, 2021
…edis#9313)

This aims to solve the issue in CONFIG SET maxmemory can only set maxmemory to up
to 9223372036854775807 (2^63) while the maxmemory should be ULLONG.
Added a memtoull function to convert a string representing an amount of memory
into the number of bytes (similar to memtoll but for ull). Also added ull2string to
convert a ULLong to string (Similar to ll2string).
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Sep 8, 2021
This one follow redis#9313 and goes deeper (validation of config file parsing)

Move the check/update logic to a new updateClientOutputBufferLimit
function. So that it can be used in CONFIG SET and config file parsing.
warrick1016 pushed a commit to ctripcorp/Redis-On-Rocks that referenced this pull request Aug 29, 2025
…edis#9313)

This aims to solve the issue in CONFIG SET maxmemory can only set maxmemory to up
to 9223372036854775807 (2^63) while the maxmemory should be ULLONG.
Added a memtoull function to convert a string representing an amount of memory
into the number of bytes (similar to memtoll but for ull). Also added ull2string to
convert a ULLong to string (Similar to ll2string).
warrick1016 pushed a commit to ctripcorp/Redis-On-Rocks that referenced this pull request Sep 2, 2025
…edis#9313)

This aims to solve the issue in CONFIG SET maxmemory can only set maxmemory to up
to 9223372036854775807 (2^63) while the maxmemory should be ULLONG.
Added a memtoull function to convert a string representing an amount of memory
into the number of bytes (similar to memtoll but for ull). Also added ull2string to
convert a ULLong to string (Similar to ll2string).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG] The value exceeding LLONG_MAX in createULongLongConfig is invalid

5 participants