Skip to content

bug: GIT_CONFIG_COUNT parsing produces NaN when env var contains invalid value #23351

Description

@saksham-1304

Bug Description

When the GIT_CONFIG_COUNT environment variable contains an invalid (non-numeric) value, the parsing logic in shellExecutionService.ts produces NaN instead of defaulting to a safe value.

Location

packages/core/src/services/shellExecutionService.ts:409

const gitConfigCount = parseInt(baseEnv['GIT_CONFIG_COUNT'] || '0', 10);

Problem

If GIT_CONFIG_COUNT contains a non-numeric string (e.g., "invalid", "abc123", or any corrupted value), parseInt returns NaN. This causes:

  1. GIT_CONFIG_KEY_NaN and GIT_CONFIG_VALUE_NaN to be created as environment variable names
  2. GIT_CONFIG_COUNT to be set to "NaN" (string)
  3. Potential silent failures in git operations that depend on these environment variables

Steps to Reproduce

  1. Set GIT_CONFIG_COUNT=invalid in the environment
  2. Run a shell command through Gemini CLI in non-interactive mode
  3. Observe that the environment variables are corrupted with NaN values

Expected Behavior

The code should validate the parsed integer and default to 0 if the value is NaN, ensuring git configuration environment variables are always valid.

Proposed Fix

const parsedCount = parseInt(baseEnv['GIT_CONFIG_COUNT'] || '0', 10);
const gitConfigCount = Number.isNaN(parsedCount) ? 0 : parsedCount;

Environment

  • OS: All platforms
  • Node.js: >=20.0.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreIssues related to User Interface, OS Support, Core Functionalitystatus/need-triageIssues that need to be triaged by the triage automation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions