Project

General

Profile

Bug #35530

save_to_file macro does not work if the thing being saved contains a heredoc terminated with EOF

Added by Adam Ruzicka 2 months ago. Updated 1 day ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Templates
Target version:
-
Fixed in Releases:
Found in Releases:
Red Hat JIRA:

Description

save_to_file does

cat <<EOF >$file
$content
EOF

but if `$content` contains a heredoc terminated with `EOF`, it terminates the heredoc that save_to_file creates.

Associated revisions

Revision 38365d82 (diff)
Added by Adam Ruzicka 2 months ago

Fixes #35530 - Make save_to_file macro safer (#9426)

  • Fixes #35530 - Make save_to_file macro safer

save_to_file does

cat <<EOF >$file
$content
EOF

but if `$content` contains a heredoc terminated with `EOF`, it
terminates the heredoc that save_to_file creates.

This fix prefixes each line of $content with a space and then pipes the
result into sed to trim the one leading space away.

  • Fixes #35530 - Update snapshots

Revision 767fea26 (diff)
Added by Adam Ruzicka about 2 months ago

Refs #35530 - Alternative approach to save_to_file

save_to_macro generates a command using cat and a heredoc string.
However, if the content to be written contains a heredoc using the same
delimiter, save_to_macro's heredoc will be terminated by it, leading to
mangled parts of the original content and save_to_macro being left
scattered around.

Another issue is, that when the content to be written contains things
like shell variables or subprocesses, those get evaluated when the
content is being written out. This may be desirable in some cases and
surprising in others.

In this commit:
- delimiter suffix is based on a hash of the file being written
- be more explicit about when the file is truncated
- Allow optionally storing the content explicitly, without letting the
shell replace variables in it. Note, this requires base64 utility to
be available on the target machine.
- make the macro work with files with special characters in their names

Revision 5537d830 (diff)
Added by Sayan Das about 24 hours ago

Refs #35530 - Dont use shellescape on the filename

History

#1 Updated by The Foreman Bot 2 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/9426 added

#2 Updated by Peter Ondrejka 2 months ago

  • Bugzilla link set to 2127940

#3 Updated by The Foreman Bot 2 months ago

  • Fixed in Releases 3.5.0 added

#4 Updated by Adam Ruzicka 2 months ago

  • Status changed from Ready For Testing to Closed

#5 Updated by The Foreman Bot 2 months ago

  • Pull request https://github.com/theforeman/foreman/pull/9436 added

#6 Updated by The Foreman Bot 4 days ago

  • Pull request https://github.com/theforeman/foreman/pull/9523 added

#7 Updated by Ewoud Kohl van Wijngaarden 1 day ago

  • Triaged changed from No to Yes

Also available in: Atom PDF