diff --git a/CHANGELOG.md b/CHANGELOG.md index fc8f5f789a..85d3fe90d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Bugfixes: * Fixed building with dconf enabled but gio disabled (`-DENABLE_GIO=OFF`). (General) * Fixed division by zero when calculating disk I/O rates over a sub-millisecond sampling interval. (Top) +* Fixed missing range validation on `--temp-ndigits`, `--percent-ndigits`, `--fraction-ndigits`, and `--freq-ndigits`. (General) # 2.72.0 diff --git a/doc/help.json b/doc/help.json index 5d29a8bb63..60386b86ae 100644 --- a/doc/help.json +++ b/doc/help.json @@ -966,7 +966,7 @@ { "long": "fraction-ndigits", "desc": "Set the number of decimal places to use when printing fractional values", - "remark": "If negative, the number of digits will be automatically determined based on the value", + "remark": "If -1, the number of digits will be automatically determined based on the value", "arg": { "type": "num", "default": -1 diff --git a/src/options/display.c b/src/options/display.c index 25d807efe8..7733d5752b 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -831,7 +831,12 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key {}, }); } else if (ffStrEqualsIgnCase(subkey, "ndigits")) { - options->tempNdigits = (uint8_t) ffOptionParseUInt32(key, value); + uint32_t num = ffOptionParseUInt32(key, value); + if (num > 9) { + fprintf(stderr, "Error: %s must be between 0 and 9\n", key); + exit(479); + } + options->tempNdigits = (uint8_t) num; } else if (ffStrEqualsIgnCase(subkey, "color-green")) { ffOptionParseColor(value, &options->tempColorGreen); } else if (ffStrEqualsIgnCase(subkey, "color-yellow")) { @@ -853,7 +858,12 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key if (ffStrEqualsIgnCase(subkey, "type")) { options->percentType = (uint8_t) ffOptionParseUInt32(key, value); } else if (ffStrEqualsIgnCase(subkey, "ndigits")) { - options->percentNdigits = (uint8_t) ffOptionParseUInt32(key, value); + uint32_t num = ffOptionParseUInt32(key, value); + if (num > 9) { + fprintf(stderr, "Error: %s must be between 0 and 9\n", key); + exit(479); + } + options->percentNdigits = (uint8_t) num; } else if (ffStrEqualsIgnCase(subkey, "color-green")) { ffOptionParseColor(value, &options->percentColorGreen); } else if (ffStrEqualsIgnCase(subkey, "color-yellow")) { @@ -873,7 +883,12 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key return false; } } else if (ffStrEqualsIgnCase(key, "--fraction-ndigits")) { - options->fractionNdigits = (int8_t) ffOptionParseInt32(key, value); + int32_t num = ffOptionParseInt32(key, value); + if (num < -1 || num > 9) { + fprintf(stderr, "Error: %s must be between -1 and 9\n", key); + exit(479); + } + options->fractionNdigits = (int8_t) num; } else if (ffStrEqualsIgnCase(key, "--fraction-trailing-zeros")) { options->fractionTrailingZeros = (FFFractionTrailingZerosType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { { "default", FF_FRACTION_TRAILING_ZEROS_TYPE_DEFAULT }, @@ -917,7 +932,12 @@ bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key } else if (ffStrStartsWithIgnCase(key, "--freq-")) { const char* subkey = key + strlen("--freq-"); if (ffStrEqualsIgnCase(subkey, "ndigits")) { - options->freqNdigits = (int8_t) ffOptionParseInt32(key, value); + int32_t num = ffOptionParseInt32(key, value); + if (num < -1 || num > 9) { + fprintf(stderr, "Error: %s must be between -1 and 9\n", key); + exit(479); + } + options->freqNdigits = (int8_t) num; } else if (ffStrEqualsIgnCase(subkey, "space-before-unit")) { options->freqSpaceBeforeUnit = (FFSpaceBeforeUnitType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { { "default", FF_SPACE_BEFORE_UNIT_DEFAULT },