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:

int compute(const char *p);
void f(void)
{
    // FLAGGED: Hardcoded absolute filesystem path
    const char *a = "/etc/passwd";
    // FLAGGED: Hardcoded absolute filesystem path
    const char *b = "C:\\Users\\foo";
    const char *c = "relative/path.txt";
    const char *d = "just a message";
    // FLAGGED: Hardcoded absolute filesystem path
    const char *e = "/usr/local/bin";
    // FLAGGED: Hardcoded absolute filesystem path
    int n = compute("/var/log/app.log");
    (void)a; (void)b; (void)c; (void)d; (void)e; (void)n;
}

Remediation

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

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved