Skip to content

Mark Cwd::getcwd results as tainted under -T #1125

Description

@fglock

Summary

Under taint mode (-T), PerlOnJava returns the value of Cwd::getcwd() as a clean scalar. Standard Perl marks this operating-system-derived value as tainted.

This affects both PerlOnJava backends and causes Data::Compare 1.29's taint test to enter plugin discovery when it should disable plugins.

Minimal reproducer

use strict;
use warnings;
use Scalar::Util qw(tainted);
use Cwd qw(getcwd);
print tainted(getcwd()) ? "tainted\n" : "clean\n";

Run with taint mode enabled:

perl -T reproducer.pl
jperl -T reproducer.pl
jperl --interpreter -T reproducer.pl

Results:

  • system Perl: tainted
  • PerlOnJava JVM backend: clean
  • PerlOnJava interpreter backend: clean

CPAN integration evidence

CPAN random-tester run 20260825-173145-22349 tested the pure-Perl Data::Compare 1.29 distribution.

  • System Perl: all 17 test files and 77 assertions pass.
  • PerlOnJava: the other 16 test files pass with 76 assertions; t/taint.t exits before producing its assertion.
  • Running t/realtainttest directly fails on both PerlOnJava backends with Insecure dependency in chdir while running with -T switch from File::Find.

Data::Compare intentionally guards plugin discovery with logic equivalent to:

register_plugins() unless tainted(getcwd()) || !chdir($cwd);

Because PerlOnJava reports getcwd() as clean, it scans plugin directories through File::Find. That later reaches a correctly enforced taint check and aborts. Standard Perl skips plugin discovery as intended.

Expected behavior

Cwd::getcwd() should return a tainted scalar while -T is active, matching standard Perl.

Acceptance criteria

  • Add a focused project regression test, validated first with standard Perl, for tainted(Cwd::getcwd()) under -T.
  • Make the regression pass on both the JVM and interpreter backends.
  • Make Data::Compare 1.29's unchanged t/taint.t pass.
  • Preserve current behavior when taint mode is not enabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions