Skip to content
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

Fixes #9299: prefixes ending with a '/' do not get appended a '-' #258

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion modules/tftp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ def pxeconfig_file mac
end

def self.fetch_boot_file dst, src
filename = dst + '-' + src.split("/")[-1]

filename = boot_filename(dst, src)
destination = Pathname.new(File.expand_path(filename, Proxy::TFTP::Plugin.settings.tftproot)).cleanpath
tftproot = Pathname.new(Proxy::TFTP::Plugin.settings.tftproot).cleanpath
raise "TFTP destination outside of tftproot" unless destination.to_s.start_with?(tftproot.to_s)
Expand All @@ -104,4 +105,9 @@ def self.fetch_boot_file dst, src

::Proxy::HttpDownloads.start_download(src.to_s, destination.to_s)
end

def self.boot_filename(dst, src)
# Do not append a '-' if the dst is a directory path
dst.end_with?('/') ? dst + src.split("/")[-1] : dst + '-' + src.split("/")[-1]
end
end
7 changes: 7 additions & 0 deletions test/tftp/tftp_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ def test_paths_outside_tftp_directory_raise_errors
end
end

def test_boot_filename_has_no_dash_when_prefix_ends_with_slash
assert_equal "a/b/c/somefile", Proxy::TFTP.boot_filename('a/b/c/', '/d/somefile')
end

def test_boot_filename_uses_dash_when_prefix_does_not_end_with_slash
assert_equal "a/b/c-somefile", Proxy::TFTP.boot_filename('a/b/c', '/d/somefile')
end
end