Skip to content

Commit

Permalink
avoid integer overflow for cache-limit
Browse files Browse the repository at this point in the history
Without this, "mb * 1024 * 1024" overflows for mb >= 2048. The result is
then cast into size_t, which is unsigned and usually a 64-bit integer.
The end result is, that the cache is now basically unlimited.

Fix this by making sure that the multiplication operated on 64-bit
values.
  • Loading branch information
michaelolbrich committed Jun 21, 2023
1 parent 9d397ef commit ae5a725
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion daemon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,7 @@ int main(int argc, char **argv)
int mb = atoi(optarg);

if (!errno) {
cache_size_limit = mb * 1024 * 1024;
cache_size_limit = mb * 1024L * 1024;
}
} else {
usage("Error: --cache-limit requires argument");
Expand Down

0 comments on commit ae5a725

Please sign in to comment.