From 89d6ef33542f5dbe29bc8f929fcb552599d99aaa Mon Sep 17 00:00:00 2001 From: woahwhattheheck Date: Sun, 20 Sep 2026 14:19:16 -0400 Subject: [PATCH 1/2] Reject NaN numeric parameters --- libcperciva/util/parsenum.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libcperciva/util/parsenum.h b/libcperciva/util/parsenum.h index d8406c9b..3841361f 100644 --- a/libcperciva/util/parsenum.h +++ b/libcperciva/util/parsenum.h @@ -151,6 +151,8 @@ parsenum_float(const char * s, double min, double max, int trailing) val = strtod(s, &eptr); if (eptr == s || (!trailing && (*eptr != '\0'))) errno = EINVAL; + else if (isnan(val)) + errno = EINVAL; else if ((val < min) || (val > max)) errno = ERANGE; return (val); From b3b46e59e1de1a2638e8ceb1bfad53fa32e0f7b5 Mon Sep 17 00:00:00 2001 From: woahwhattheheck Date: Sun, 20 Sep 2026 14:19:18 -0400 Subject: [PATCH 2/2] Test rejection of NaN resource options --- tests/09-explicit-params.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/09-explicit-params.sh b/tests/09-explicit-params.sh index 7b75b05b..73c29239 100644 --- a/tests/09-explicit-params.sh +++ b/tests/09-explicit-params.sh @@ -63,4 +63,17 @@ scenario_cmd() { enc -p 12 "${reference_file}" 2>&1 | \ grep -q "If -p is set, --logN and -r must also be set" echo $? > "${c_exitfile}" + + # NaN is not a numeric value within any bounded resource range. + setup_check "scrypt rejects NaN maxmem fraction" + ${c_valgrind_cmd} "${bindir}/scrypt" info -m NaN \ + "${scriptdir}/verify-strings/test_scrypt_good.enc" 2>&1 | \ + grep -q "Invalid option: -m NaN" + echo $? > "${c_exitfile}" + + setup_check "scrypt rejects NaN max time" + ${c_valgrind_cmd} "${bindir}/scrypt" info -t NaN \ + "${scriptdir}/verify-strings/test_scrypt_good.enc" 2>&1 | \ + grep -q "Invalid option: -t NaN" + echo $? > "${c_exitfile}" }