Skip to content

vmadm create crashes with unhelpful TypeError when given invalid brand name #1168

@nwilkens

Description

@nwilkens

Summary

When creating a VM with an invalid brand value (e.g., "smartos"), vmadm crashes with a JavaScript TypeError and core dump instead of providing a helpful validation error message.

Steps to Reproduce

# Create a payload with an invalid brand
cat > test.json <<EOF2
{
  "brand": "smartos",
  "alias": "test",
  "image_uuid": "2f1dc911-6401-4fa4-8e9d-67ea2e39c271",
  "max_physical_memory": 512,
  "quota": 10
}
EOF2

vmadm create -f test.json

Actual Behavior

Uncaught TypeError: Cannot read property 'features' of undefined
 
FROM
fixPayloadMemory (/usr/vm/node_modules/VM.js:4626:29)
applyZoneDefaults (/usr/vm/node_modules/VM.js:4908:5)
normalizePayload (/usr/vm/node_modules/VM.js:10005:9)
...
Abort (core dumped)

Expected Behavior

A clear validation error such as:

vmadm create: error: invalid brand "smartos". Valid brands are: joyent, joyent-minimal, lx, kvm, bhyve

Root Cause

In src/vm/node_modules/VM.js:4626, the code accesses BRAND_OPTIONS[brand].features without first checking if BRAND_OPTIONS[brand] exists:

if (BRAND_OPTIONS[brand].features.default_memory_overhead

When brand is not a valid key in BRAND_OPTIONS, this returns undefined, causing the TypeError.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions