I just completed a CTF machine, but my brain has a hard time figuring out why this worked, so I thought to ask because I won't be able to sleep until I know! My question is regarding the use of the relative paths.
Below is the source code of a Ruby script that includes the list_from_file
function which uses a relative path for reading the dependencies.yml
file.
henry@precious:~$ cat /opt/update_dependencies.rb# Compare installed dependencies with those specified in "dependencies.yml"require "yaml"require 'rubygems'# TODO: update versions automaticallydef update_gems()enddef list_from_file YAML.load(File.read("dependencies.yml"))enddef list_local_gems Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.map{|g| [g.name, g.version.to_s]}endgems_file = list_from_filegems_local = list_local_gemsgems_file.each do |file_name, file_version| gems_local.each do |local_name, local_version| if(file_name == local_name) if(file_version != local_version) puts "Installed version differs from the one specified in file: " + local_name else puts "Installed version is equals to the one specified in file: " + local_name end end endend
My limited knowledge infers that when I execute this script, it will only search to find the dependencies.yml
file in the same directory as the script, in this case, /opt/
.
However, this is not true! When I create this file within the /tmp
directory, and then run the script, it actually picks it up!
I searched and read some articles as well as other stackoverflow posts regarding relative vs. absolute paths but none actually provided an explanation for why this is happening.
I am sorry in advance if I missed any closely-related post!