From b60f28bee9355dc4696030c1f193b01316c42c81 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Fri, 10 Jul 2015 18:54:22 +0200 Subject: [PATCH] run/load/tftp: detect bad directory If a user has e.g. /tftpboot/x86 as directory and configures base_dir=/tftboot and offset_dir=/x86, this leads to bad behavior as the load module creates a symlink /tftpboot/x86/ -> in this case instead of the desired /tftpboot/x86 -> Furthermore, the module works on /tftpboot/x86/config-00-00-00-00-00-00 and /tftpboot/x86//config-00-00-00-00-00-00 afterwards, which looks bad too. As there is no warning at all, this can be hard to debug. The commit adds an appropriate check with error message and exit -1 on an existing directory. Fixes #1630 --- tool/run/load/tftp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tool/run/load/tftp b/tool/run/load/tftp index 677ebb41b..269a3e936 100644 --- a/tool/run/load/tftp +++ b/tool/run/load/tftp @@ -47,6 +47,14 @@ proc generate_tftp_config { } { set tftp_offset_dir [load_tftp_offset_dir] if {[string length $tftp_base_dir] > 0 && [string length $tftp_offset_dir] > 0} { + + # if the link target exists as directory this leads to bad behavior + if {[file exists $tftp_base_dir$tftp_offset_dir] && + [string compare [file type $tftp_base_dir$tftp_offset_dir] "directory"] == 0} { + + puts stderr "Error: TFTP symlink target $tftp_base_dir$tftp_offset_dir is a directory" + exit -1 + } exec ln -nfs "[pwd]" "$tftp_base_dir$tftp_offset_dir" set tftp_base ""