fix(version): prevent panic on empty or invalid version string in Compare - #645
SatyamPandey-07 wants to merge 1 commit into
Conversation
|
Welcome to NodeWright, @SatyamPandey-07! Thanks for your first pull request. Before review, please ensure:
A maintainer will review this soon. |
|
✅ Every non-bot commit on this pull request is now signed off and signed. Thanks! |
25c2e2c to
f91a0fb
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: NVIDIA/nodewright/.coderabbit.yaml Review profile: ASSERTIVE Plan: Enterprise Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review. 📝 WalkthroughWalkthrough
Priority: ⬆️ High Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Comment |
|
@lockwobr Hi, just bumping this PR in case it slipped through your notifications. Let me know if you need any changes or further testing! |
|
@SatyamPandey-07 Looks like maybe you commited two files you didnt mean too. Please remove them. They are not passing a test which is making your pr red. |
…pare Signed-off-by: Satyam Pandey <satyam53@tsecol.onmicrosoft.com>
01ec89d to
c81378f
Compare
|
@lockwobr Thanks for the heads up! I have rebased the branch onto the latest main, squashed the commits into a single signed and DCO-compliant commit. The PR now only modifies operator/internal/version/version.go and operator/internal/version/version_test.go. All 29 unit tests pass. |
Related Issue
Fixes #644
Changes Proposed
operator/internal/version/version.go: Validated inputs inCompare(version1, version2 string) intusingIsValid(version1)andIsValid(version2)prior to accessing slice indicesversion1[0]andversion2[0]. If either version is empty or invalid semver,Comparenow returns-2. This prevents runtime index-out-of-range panics when reconciling nodes with missing or empty version state annotations and fulfills the error contract expected byskyhook_controller.go(if comparison == -2).operator/internal/version/version_test.go: Added table-driven test cases verifying thatComparereturns-2when given an empty string on the left, an empty string on the right, empty strings on both sides, or invalid semver strings (e.g.,"dev").How Has This Been Tested?
version_test.goverifying thatComparereturns-2for empty strings on either or both sides, as well as invalid semver inputs, alongside existing ordering test cases.operator/internal/controller/skyhook_controller.goline 1968 receives-2on invalid/empty version annotations and properly returns a reconciliation error instead of crashing.Checklist