Hardcoded absolute filesystem path

ID

c.portability.hardcoded_absolute_path

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Portability

Language

C / C++

Description

This string literal is a hardcoded absolute filesystem path, which is not portable: the path may not exist on other machines or operating systems (Unix vs Windows layouts differ). Derive the path from configuration, an environment variable, or a runtime base directory instead of hardcoding it.

Rationale

This string literal is a hardcoded absolute filesystem path, which is not portable: the path may not exist on other machines or operating systems (Unix vs Windows layouts differ). Derive the path from configuration, an environment variable, or a runtime base directory instead of hardcoding it.

The following code illustrates the pattern detected by this rule:

void f(void)
{
    // FLAGGED: Hardcoded absolute filesystem path
    const char *a = "/etc/passwd";
    // FLAGGED: Hardcoded absolute filesystem path
    const char *b = "C:\\Users\\foo";

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.