mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-02 04:46:41 -05:00
fix: reject func.readdir counts that overflow an int
- std::stoi threw std::out_of_range for a concurrency or queue depth above INT_MAX, e.g. cor:99999999999. Given at mount, mergerfs aborted. Set at runtime through .mergerfs, the daemon shut down and the mount went away, or with process-thread-count>0 the request never got a reply. - Parse with str::from, which reports the overflow, and reject the value like any other malformed one. - Also reject a queue depth whose product with the concurrency overflows an int, e.g. cor:2147483647:2147483647, instead of wrapping it. - tests.cpp covers both.
This commit is contained in:
parent
fe2d94dd1c
commit
7d677d1a37
2 changed files with 33 additions and 5 deletions
|
|
@ -22,11 +22,14 @@
|
|||
#include "fuse_readdir_cosr.hpp"
|
||||
#include "fuse_readdir_seq.hpp"
|
||||
|
||||
#include "from_string.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
#include <regex>
|
||||
|
||||
// Regex:
|
||||
|
|
@ -56,11 +59,18 @@ _read_cfg(const std::string_view str_,
|
|||
re);
|
||||
if(matched)
|
||||
{
|
||||
type = match[1];
|
||||
int rv = 0;
|
||||
|
||||
// A count too large for an int leaves type empty, so the value
|
||||
// is rejected as invalid instead of throwing.
|
||||
if(match[2].matched)
|
||||
concurrency = std::stoi(match[2]);
|
||||
if(match[3].matched)
|
||||
max_queue_depth = std::stoi(match[3]);
|
||||
rv = str::from(std::string_view(match[2].first,match[2].length()),
|
||||
&concurrency);
|
||||
if((rv == 0) && match[3].matched)
|
||||
rv = str::from(std::string_view(match[3].first,match[3].length()),
|
||||
&max_queue_depth);
|
||||
if(rv == 0)
|
||||
type = match[1];
|
||||
}
|
||||
|
||||
if(concurrency == 0)
|
||||
|
|
@ -80,7 +90,11 @@ _read_cfg(const std::string_view str_,
|
|||
if(max_queue_depth <= 0)
|
||||
max_queue_depth = 2;
|
||||
|
||||
max_queue_depth *= concurrency;
|
||||
// Reject a queue depth whose product overflows instead of wrapping.
|
||||
if(max_queue_depth > (std::numeric_limits<int>::max() / concurrency))
|
||||
type.clear();
|
||||
else
|
||||
max_queue_depth *= concurrency;
|
||||
|
||||
type_ = type;
|
||||
concurrency_ = concurrency;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue