Skip to content

Improper sed -i Behavior #549

Closed
Closed

Description

@danktrapking-gif

When -i is provided without an attached suffix, uutils/sed incorrectly consumes the subsequent positional argument (the sed expression) as the backup suffix. This causes the target filename to be evaluated as a sed script, resulting in parsing errors.
In GNU sed, the suffix for -i is optional and must be concatenated directly without whitespace

Reproduction Steps:

echo "foo" > test.txt
sed -i 's/foo/bar/' test.txt

Observed Output:

sed: <script argument 1>:1:1: error: undefined label `est.txt'

Expected Output:

Exit code 0, test.txt modified in-place with contents "bar", no backup file created.

Activity

  1. danktrapking-gif commented on Sep 5, 2026

    @danktrapking-gif
    Author

    I've diffed a working patch that addresses this in instances where I experienced it, which was primarily while building the kernel and potentially most gentoo ebuilds. I also stumbled upon another bug in fast_regex.rs while making a grub config with os-prober in use where NEEDS_FANCY_RE misinterprets multi-digit octal literals like \134 as back-references and aborts in byte mode. So both of these patches will be included.

    These patches are AI assisted though, hence why I don't want to make a formal PR and just assume AI code contributions to any extent are accepted. But I would like to still share the fixes. there was another bug in fast_io.rs that prevented the full test suite from running, but I haven't run into a real world use-case where that actually mattered outside of the test suite, therefore I didn't investigate.

    uutils-sed-fixes.patch

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions