From e3cc976ae3f211727e3fae702776aacca46efb0c Mon Sep 17 00:00:00 2001 From: bitflash-maintainer Date: Wed, 2 Sep 2026 16:42:39 +0000 Subject: log: reject a -maxdebugfilesize that is not a plain count of MB atoi64() is strtoll() with the endptr discarded, so it yields 0 for anything it cannot read. -maxdebugfilesize=1G and -maxdebugfilesize=1024MB both parsed as 0, which the roll reads as "never roll" -- indistinguishable from requesting that deliberately, and silent. An operator who wrote a unit suffix got no rotation and no warning. Only a negative value said anything. The multiplication was unchecked as well: a large enough N made nMB * 1024 * 1024 overflow to a negative cap, which disables the roll too. Parse with strtoll() and its endptr, and reject trailing characters, ERANGE, negatives, and any value that would overflow the byte cap -- each reported with the reason and the cap being kept. 0 still means never roll and is still accepted without comment. --- src/main_gui.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/main_gui.cpp') diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 163d78e..0e64985 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -210,10 +210,33 @@ static void ParseStartupArguments(int argc, char* argv[]) string strMaxDebugSize = argval2(argc, argv, "/maxdebugfilesize", "-maxdebugfilesize"); if (!strMaxDebugSize.empty()) { - int64 nMB = atoi64(strMaxDebugSize.c_str()); - if (nMB < 0) - fprintf(stderr, "Ignoring /maxdebugfilesize=%s: not a size in MB\n", - strMaxDebugSize.c_str()); + // Parsed with atoi64() before, which is strtoll() with the endptr + // thrown away: it returns 0 for anything it cannot read, so + // /maxdebugfilesize=1G and =1024MB both came out as 0 -- "never + // roll", identical to asking for that on purpose, with nothing said + // to the operator. The old code also multiplied without a range + // check, so a big enough N wrapped to a negative cap, which the roll + // reads as "off" too. Every rejection is now reported and leaves the + // default in place; the value is a plain count of MB, no suffix. + const char* psz = strMaxDebugSize.c_str(); + char* pszEnd = NULL; + errno = 0; + int64 nMB = strtoll(psz, &pszEnd, 10); + // INT64_MAX, without depending on which limits header this tree pulls in. + const int64 nMaxMB = (int64)((~(uint64)0) >> 1) / (1024 * 1024); + const char* pszWhy = NULL; + if (pszEnd == psz) + pszWhy = "not a number"; + else if (*pszEnd != '\0') + pszWhy = "trailing characters -- the value is a count of MB, with no unit suffix"; + else if (errno == ERANGE || nMB < 0) + pszWhy = "not a size in MB"; + else if (nMB > nMaxMB) + pszWhy = "larger than a file size can be"; + if (pszWhy) + fprintf(stderr, "Ignoring /maxdebugfilesize=%s: %s (keeping %lld MB)\n", + strMaxDebugSize.c_str(), pszWhy, + (long long)(nMaxDebugFileSize / 1024 / 1024)); else nMaxDebugFileSize = nMB * 1024 * 1024; } -- cgit v1.2.3