Skip to content

When creating a Generator instance using zero-value initialization (Generator{}), calling AddProcessEnv causes a nil pointer panic. #790

@andreaskaris

Description

@andreaskaris

Description

When creating a Generator instance using zero-value initialization (Generator{}), calling AddProcessEnv causes a nil pointer panic.

Steps to Reproduce

  1. Create a Generator using zero-value initialization instead of New():
    g := generate.Generator{}
  2. Call AddProcessEnv on the generator:
    g.AddProcessEnv("KEY", "value")
  3. The program panics with a nil pointer dereference

Expected Behavior

AddProcessEnv should work correctly regardless of whether the Generator was created using New() or zero-value initialization.

Actual Behavior

The program panics because the envMap field is nil when the Generator is created using zero-value initialization, and the addEnv helper function attempts to write to this nil map.

Root Cause

The addEnv function in generate.go writes to g.envMap without checking if it has been initialized. When using zero-value initialization, this field remains nil.

Environment

  • Component: generate package
  • Affected function: AddProcessEnv (via addEnv helper)

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