Skip to content

Safely escape values written through sed - #610

Merged
ExtremeFiretop merged 1 commit into
ExtremeFiretop:devfrom
maghuro:fix/settings-sed-escaping
Sep 24, 2026
Merged

ExtremeFiretop merged 1 commit into
ExtremeFiretop:devfrom
maghuro:fix/settings-sed-escaping

Conversation

@maghuro

@maghuro maghuro commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Safely escape configuration values before using them in sed replacement expressions.

Problem

Update_Custom_Settings() writes several setting values back into the configuration file using sed substitutions.

One path currently escapes a set of characters that does not include ampersand.

In a sed replacement expression, ampersand has special meaning: it expands to the entire text matched by the search expression.

For example, a setting value such as:

/tmp/a&b

can corrupt the configuration line because the ampersand is interpreted by sed instead of being written literally.

Backslashes also have special meaning in sed replacement strings and need to be escaped consistently.

Fix

Before inserting setting values into sed replacement expressions, escape the three characters that are significant for this usage:

  • slash
  • ampersand
  • backslash

The same escaping expression is now used consistently by all three replacement paths in Update_Custom_Settings().

The value is also passed through printf instead of echo so that its contents are not subject to implementation-specific echo escape handling.

Validation

The replacement behavior was tested with both regular sed and BusyBox sed using values containing:

  • normal paths
  • forward slashes
  • ampersands
  • backslashes
  • combinations of ampersands and backslashes

Values are preserved correctly in the resulting configuration assignment.

The previous behavior with an ampersand was also reproduced and resulted in configuration-line corruption.

@maghuro
maghuro force-pushed the fix/settings-sed-escaping branch from 3029456 to 190edc6 Compare September 24, 2026 00:48
@ExtremeFiretop

Copy link
Copy Markdown
Owner

@Martinski4GitHub

Considering this PR basically does nothing but extend your existing fix from PR:
#590

I'll merge it in as is.

@ExtremeFiretop
ExtremeFiretop merged commit 0ef0824 into ExtremeFiretop:dev Sep 24, 2026
1 check passed
ExtremeFiretop added a commit that referenced this pull request Sep 24, 2026
Extension of PR: #590 and #610

Fix settings values that contain an = character being cut off when MerlinAU reads them back... For example, foo=bar@example.com would previously be read as foo.
@ExtremeFiretop

Copy link
Copy Markdown
Owner

I extended this PR even further in commit: 4e779db

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants