vmadm create: reject invalid brand cleanly (#1168)#1179
Draft
nwilkens wants to merge 1 commit into
Draft
Conversation
normalizePayload() applies zone defaults (which calls fixPayloadMemory via applyZoneDefaults) before validating that the requested brand is supported. Both helpers index BRAND_OPTIONS[brand] unguarded, so an unknown brand crashes vmadm with: Uncaught TypeError: Cannot read property 'features' of undefined FROM fixPayloadMemory (/usr/vm/node_modules/VM.js) applyZoneDefaults (...) normalizePayload (...) Hoist a brand-existence check above the apply-defaults branch so an explicit unsupported brand returns "Unsupported brand: <name>" via the callback instead of aborting. Add a defensive assert in fixPayloadMemory so any future call path that bypasses validation still surfaces a structured error rather than a TypeError. Includes a regression test in test-create.js that calls VM.create with brand="smartos" and asserts the callback receives a clean "Unsupported brand" error. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
Probably beats the crud out of this (where I took a SmartOS UI json and Make sure you file an OS ticket for this, too. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1168.
normalizePayload()runsapplyZoneDefaults()(andfixPayloadMemory()) before the existing invalid-brand check. Both indexBRAND_OPTIONS[brand].features.*unguarded, so an unsupported brand throwsTypeError: Cannot read property 'features' of undefinedand dumps core instead of returning the clean error path.normalizePayload. Explicit unsupported brands now returnError: Unsupported brand: <name>via callback. No-brand and valid-brand paths are unchanged.assertinfixPayloadMemoryso future call paths that skip upfront validation fail with a clear message rather than silently TypeError'ing on one of the ~9 unguardedBRAND_OPTIONS[brand]dereferences in this file.test-create.jscallsVM.create({brand: "smartos", ...})and asserts the callback getsUnsupported brand.