Skip to content

getFlagRef panics on custom pflag.Value wrappers with value-backed value fields #160

Description

@theZMC

fangs panics while generating a configuration summary when it encounters a custom pflag.Value where the implementation is a pointer to a struct, but the underlying value backing the implementation is not a pointer.

This behavior was first noticed in this issue in zarf. zarf vendors syft under zarf tools sbom to make it readily available to zarf users when operating in an airgapped environment.

When running zarf tools sbom config, the vendored syft cobra command calls fangs.SummarizeCommand which ascends the cobra command graph to the root then walks all config for the entire cobra command tree. zarf also vendors yq which has a custom pflag.Value implementation: unwrapScalarFlagStrc. This custom implementation backs the value with a plain bool and not a pointer, but fangs universally derefs the value field of any pflag.Value-implementing pointer struct type, causing it to panic when attempting to deref the pointer for this scalar.

A clean fix would be for fangs to check if a value is a pointer before attempting to deref.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions