-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filenames with backslashes causes a fatal error for Rex::Commands::Sync #1607
Comments
If you do not have qemu you can simply create a file with a backslash as a part of the filename and then try transfer it with sync_down. |
Thanks @mrmuskrat for the report! I'm afraid there are two different issues involved here. One of them indeed related to backslashes in the filename, and the other one only looks like the backslash is a problem. I expect mentioning Control characters, like
|
On a second look on an official Debian 12 image, it looks like the weirdly encoded character is more probably Apparently the problematic file mentioned in the original report somehow belongs to or related to I'll try to reproduce the original case more closely, but any hints how to end up in a comparable situation is still highly welcome. |
Oh, I've found such a file at
The original error of
indicates that it was trying to run I confirm that escaping My current hypothesis is that the readability check during preparing the download ( |
@ferki Here's my debug log that I created today by running rex -d systemd with the Rexfile mentioned in the body of the ticket. I remember there was a reason for using sync_down instead of rsync but I don't remember what that reason was. I will reach out to the author to find out if he remembers. |
Thanks for the debug log 👍 I think the most relevant addition info is here:
indicating that the I could successfully recreate the scenario when manually creating a directory with the problematic path name including Notes for implementorsBased on what I learned so far, both identified cases could be handled on this issue, probably no need to split into different cases after all. Since currently there are no tests for sync functionality yet, working on this would require handling that first (=writing tests for the current behavior), and then adding a failing test case for this issue before solving. Until then the possible workarounds are to:
diff --git a/lib/Rex/Interface/Fs/Base.pm b/lib/Rex/Interface/Fs/Base.pm
index e42b75fb..a0820394 100644
--- a/lib/Rex/Interface/Fs/Base.pm
+++ b/lib/Rex/Interface/Fs/Base.pm
@@ -199,7 +199,7 @@ sub _normalize_path {
sub _quotepath {
my ( $self, $p ) = @_;
- $p =~ s/([\@\$\% ])/\\$1/g;
+ $p =~ s/([\\\@\$\% ])/\\$1/g;
return $p;
} |
Describe the bug
Rex terminates with errors (the error varies based on where it is thrown) if dealing with a filename containing backslashes.
Example:
[2023-09-20 11:16:14] INFO - Running task systemd on host
[2023-09-20 11:17:18] ERROR - Error executing task:
[2023-09-20 11:17:18] ERROR - Error running chmod 0755 /Users/mmusgrove/tmp/host/fs/etc/systemd/system/dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants at /Users/mmusgrove/perl5/perlbrew/perls/perl-5.26.3/lib/site_perl/5.26.3/Rex/Interface/Fs/Base.pm line 149, <> line 145.
[2023-09-20 11:17:18] ERROR - 1 out of 1 task(s) failed:
[2023-09-20 11:17:18] ERROR - systemd failed on host
[2023-09-20 11:17:18] ERROR - Error running chmod 0755 /Users/mmusgrove/tmp/host/fs/etc/systemd/system/dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants at /Users/mmusgrove/perl5/perlbrew/perls/perl-5.26.3/lib/site_perl/5.26.3/Rex/Interface/Fs/Base.pm line 149, <> line 145.
I was attempting to use rsync_down on /etc/systemd and it encountered this file:
[root@host ~]# ls -al /etc/systemd/system/dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants/qemu-guest-agent.service
lrwxrwxrwx. 1 root root 48 Oct 20 2021 '/etc/systemd/system/dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants/qemu-guest-agent.service' -> /usr/lib/systemd/system/qemu-guest-agent.service
The host/fs/etc/systemd/ directory exists with ~/tmp.
The problem seems to be that Rex::Interface::Fs::Base::_quotepath is not handling backslashes. I can fix it if I override that method as follows:
Expected behavior
I would expect the sync_down to function the same regardless of whether or not the filename contains a backslash character.
How to reproduce it
Modify the following Rexfile to use a valid hostname of a Linux system with qemu installed you can connect to with ssh
mkdir -p ~/tmp/host/fs/etc/systemd # where host is the same hostname
Place the Rexfile into ~/tmp.
cd ~/tmp
rex systemd
Code example
Additional context
No response
Rex version
(R)?ex 1.14.3
Perl version
v5.26.3
Operating system running rex
Darwin Kernel Version 22.6.0: Wed Jul 5 22:21:53 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6020 arm64
Operating system managed by rex
AlmaLinux 8.8 (Sapphire Caracal)
How rex was installed?
package manager
The text was updated successfully, but these errors were encountered: