danielzzz / node-ping

a poor man's ping library (using udp scanning) for node
MIT License
332 stars 105 forks source link

Avoid modifying main process environment in getSpawnOptions #166

Open Methy42 opened 5 months ago

Methy42 commented 5 months ago

Issue Description:

In the lib/builder/linux.js file at line 121, the getSpawnOptions function sets the LANG environment variable to 'C' within the spawned process. However, this modification affects the environment of the main process as well, potentially causing unintended consequences for subsequent child processes.

Suggested Improvement:

Instead of directly modifying the process.env object with Object.assign, it's advisable to create a new object for the environment variables specific to the spawned process. This ensures that modifications are localized and do not affect the main process environment.

Proposed Code Change:

builder.getSpawnOptions = function () {
    return {
        shell: false,
        env: Object.assign({}, process.env, {LANG: 'C'}), // Create a new object to avoid modifying the main process environment
    };
};

This change prevents unintended modifications to the main process environment and ensures that only the spawned process environment is affected by the LANG setting.