Repository navigation
Bound the varargs test helpers on the last index they read - #3560
Conversation
CodeQL Code Quality reported seven java/index-out-of-bounds findings (severity error) across the two test files added in #3543 and #3546. Each finding is the same shape: a private varargs helper walks its arguments in fixed-size groups, striding by two or three, but bounds the loop on the first index of the group rather than the last. Reading namesAndIds[i + 1] under a loop guarded only by i < namesAndIds.length runs off the end whenever the caller passes a partial group. Unlike the useless-null-check and dereferenced-value-may-be-null findings on these files, this one is not a false positive. Every call site today passes a complete multiple, so nothing can throw as written, but the helpers make no such guarantee and the finding will resurface each time the files move. Bounding each loop on the last index it reads is what CodeQL's range analysis needs to see, and it turns a would-be ArrayIndexOutOfBoundsException into one fewer row for a caller that miscounts -- which a test's own assertions will catch immediately. The two production stride loops were checked and left alone: ParseUtil.hexStringToByteArray already rejects odd-length input with an explicit (len & 0x1) != 0 guard, and HkeyPerformanceDataUtil.buildCounterIndexMap starts at i = 1 and reads backwards to i - 1, so both indices are always in range. Neither was flagged. Test-only, so no CHANGELOG entry.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📜 Recent review details⏰ Context from checks skipped due to timeout. (8)
🔇 Additional comments (2)
📝 WalkthroughWalkthroughTest fixture helpers now ignore incomplete trailing varargs input. Mac GPU statistics require complete key/value pairs. Windows volume fixtures require complete pair or triple records. ChangesVarargs fixture safety
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3560 +/- ##
=========================================
Coverage 79.34% 79.34%
Complexity 3790 3790
=========================================
Files 706 706
Lines 24264 24264
Branches 4057 4057
=========================================
Hits 19253 19253
- Misses 2821 2824 +3
+ Partials 2190 2187 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
… the stub-test log noise (#3706) * Report an absent SMC once, and stop stub tests logging on every platform Two unrelated sources of log noise, both surfaced by reading a Windows CI log and finding macOS and Linux warnings in it. The production bug is in SmcUtil. Every temperature, fan speed and voltage query opens its own SMC connection, so when the AppleSMC service is absent the failure was reported at ERROR several times per sampling interval, for the life of the process. That is the normal state on a virtual machine, which does not virtualize the SMC. SmcOpenFailure latches each reason a connection could not be opened: one instance per backend holding that backend's logger, so the message is still attributed to SmcUtil or SmcUtilFFM rather than to the helper. The first occurrence is logged at a level that reflects what it means -- WARN for an absent service, which is a degradation OSHI recovers from by reporting no sensors, and ERROR for a service that is present but will not open -- and every later occurrence at DEBUG. The absent-service message now also names the likely cause. Both twins call it, and it covers the FFM-only null connect handle case, which repeated the same way. Note that this is not an Apple Silicon condition: IOKitUtil.getMatchingService ("AppleSMC") does succeed on real Apple Silicon, matching the AppleSMCKeysEndpoint subclass, so nothing here is gated on the architecture. The remaining thirteen lines were oshi-common stub tests, not platform probes. MacCentralProcessor, MacGpuStats and LinuxCentralProcessor are tested with the native boundary overridden, so nothing reaches the host and the warnings appear identically on all eight CI jobs. Each is the correct production output for the degraded path the test asks for, so an @EnabledOnOs gate would delete the test from seven jobs and still print on the eighth. The three loggers are lowered to ERROR in oshi-common's test configuration instead, which is the mechanism that file already uses for oshi.util. The keys are deliberately oshi-common only: oshi-core and oshi-core-ffm run the same classes against the real platform, where the warning means something. A full clean reactor build now emits one library log line, the deliberate LogUtilTest smoke test against the real SLF4J binding. * Fix two CodeQL Code Quality findings in MacCentralProcessorTest java/index-out-of-bounds on the accClusters varargs helper is real, and the same shape as the seven fixed in #3560: the loop strides by two but was bounded on the first index of the pair while the body reads i + 1, so an odd-length argument list runs off both the argument array and the array being built. Bounded on the last index the body reads. java/useless-null-check on the stub's sysctlInts and sysctlLongs guards has now been re-minted four times, and has been dismissed each time because the guards are load-bearing: AbstractCentralProcessor's constructor calls the overridable sysctlInt() before any subclass field initializer runs, so the maps really are null during construction. Fixing the cause instead of dismissing again. The tell was already in the file -- sysctlStrings has no field initializer and has never been flagged, while the two carrying = new HashMap<>() always are, because CodeQL reasons that the initializer is non-null without modelling the initialization order. Dropping those two initializers and assigning both maps in the constructor body, where sysctlStrings was already assigned, is behavior-identical: field initializers run immediately after super() and before the constructor body. It makes all five guards uniform and states the ordering hazard in a comment rather than leaving it implicit. The guards themselves are unchanged. No CHANGELOG entry: test-only. * Guard the JNA SMC connection handle, matching the FFM twin Review catch on the previous commit. IOServiceOpen returning KERN_SUCCESS with a null connection was handled on the FFM side but not on the JNA side, which wrapped whatever the pointer held in an IOConnect and returned it. A caller null-checks the return to decide whether the SMC is usable, so it would have proceeded with an unusable connection, every read failing silently to a sentinel and no diagnostic logged. Reports through the same latched nullConnection() the FFM backend uses, and returns null so the existing failure handling applies. The service release in the finally block is unchanged.
CodeQL Code Quality reported seven
java/index-out-of-boundsfindings (severity error) across the two test files added in #3543 and #3546:MacGpuStatsTest.java:117WindowsLogicalVolumeGroupTest.java:85,:97(×2),:108,:109,:120Each is the same shape. A private varargs helper walks its arguments in fixed-size groups, striding by two or three, but bounds the loop on the first index of the group rather than the last. Reading
namesAndIds[i + 1]under a loop guarded only byi < namesAndIds.lengthruns off the end whenever the caller passes a partial group.Unlike the
useless-null-checkanddereferenced-value-may-be-nullfindings on these files, this one is not a false positive. Every call site today passes a complete multiple, so nothing can throw as written, but the helpers make no such guarantee and the finding will resurface each time the files move.Bounding each loop on the last index it reads is what CodeQL's range analysis needs to see, and it turns a would-be
ArrayIndexOutOfBoundsExceptioninto one fewer row for a caller that miscounts — which a test's own assertions will catch immediately.The two production stride loops were checked and left alone:
ParseUtil.hexStringToByteArrayalready rejects odd-length input with an explicit(len & 0x1) != 0guard.HkeyPerformanceDataUtil.buildCounterIndexMapstarts ati = 1and reads backwards toi - 1, so both indices are always in range.Neither was flagged, and both are correct as written.
Test-only, so no CHANGELOG entry.
Full gate green on
oshi-common: spotless, checkstyle, install, forbiddenapis, javadoc, and 1264 tests successful / 0 failed.Summary by CodeRabbit