Copilot commented on code in PR #13853:
URL: https://github.com/apache/trafficserver/pull/13853#discussion_r4447814186
##########
src/proxy/http/remap/NextHopStrategyFactory.cc:
##########
@@ -23,15 +23,65 @@
#include <yaml-cpp/yaml.h>
+#include <sys/stat.h>
+
+#include <cerrno>
+#include <filesystem>
#include <fstream>
#include <cstring>
+#include <stdexcept>
+#include <string>
#include <string_view>
+#include <system_error>
+#include <utility>
+#include "records/RecCore.h"
+#include "tscore/ink_platform.h"
+#include "tscore/Layout.h"
#include "proxy/http/remap/NextHopStrategyFactory.h"
#include "proxy/http/remap/NextHopConsistentHash.h"
#include "proxy/http/remap/NextHopRoundRobin.h"
#include <tsutil/YamlCfg.h>
+namespace
+{
+// Returns the include target resolved against the configuration directory.
Layout::relative_to() calls ink_fatal() for a
+// path too long to merge, which would take down a running traffic_server on a
reload, so a target that would exceed the
+// ink_filepath_merge() length bound is rejected as a configuration error
instead.
+std::string
+config_dir_include_path(std::string const &include_target, std::string const
&fileName)
+{
+ if (RecConfigReadConfigDir().size() + include_target.size() + 4 >
PATH_NAME_MAX) {
Review Comment:
Absolute includes now pass through `RecConfigReadConfigPath()`, which
lexically removes `..` components: if `/prefix/current` links to
`/external/child`, `/prefix/current/../hosts.yaml` selects `/prefix/hosts.yaml`
rather than `/external/hosts.yaml`. The length guard also incorrectly counts
the configuration directory against absolute targets. Return absolute targets
unchanged before the guard and merge to preserve their existing lookup behavior.
##########
src/proxy/http/remap/NextHopStrategyFactory.cc:
##########
@@ -23,15 +23,65 @@
#include <yaml-cpp/yaml.h>
+#include <sys/stat.h>
+
+#include <cerrno>
+#include <filesystem>
#include <fstream>
#include <cstring>
+#include <stdexcept>
+#include <string>
#include <string_view>
+#include <system_error>
+#include <utility>
+#include "records/RecCore.h"
+#include "tscore/ink_platform.h"
+#include "tscore/Layout.h"
#include "proxy/http/remap/NextHopStrategyFactory.h"
#include "proxy/http/remap/NextHopConsistentHash.h"
#include "proxy/http/remap/NextHopRoundRobin.h"
#include <tsutil/YamlCfg.h>
+namespace
+{
+// Returns the include target resolved against the configuration directory.
Layout::relative_to() calls ink_fatal() for a
+// path too long to merge, which would take down a running traffic_server on a
reload, so a target that would exceed the
+// ink_filepath_merge() length bound is rejected as a configuration error
instead.
+std::string
+config_dir_include_path(std::string const &include_target, std::string const
&fileName)
+{
+ if (RecConfigReadConfigDir().size() + include_target.size() + 4 >
PATH_NAME_MAX) {
+ throw std::invalid_argument("'#include' path in '" + fileName + "' exceeds
the " + std::to_string(PATH_NAME_MAX) +
+ " character path limit");
+ }
+ return RecConfigReadConfigPath(nullptr, include_target.c_str());
+}
+
+// Earlier releases opened a relative include from the traffic_server working
directory, which is the install prefix.
+// ToDo: Deprecated in 11.0.0, remove in 12.0.0
+std::string
+legacy_include_path(std::string_view include_path)
+{
+ std::filesystem::path const target{include_path};
+ if (target.is_absolute()) {
+ return {};
+ }
+ return (std::filesystem::path{Layout::get()->prefix} /
target).lexically_normal().string();
Review Comment:
The compatibility lookup does not preserve the old working-directory lookup
when a legacy target contains a symlink followed by `..`. For example,
`config/current/../hosts.yaml` can previously select a release's hosts file,
while `lexically_normal()` changes it to `<prefix>/config/hosts.yaml`,
potentially selecting different next hops or failing despite the legacy file
existing. Preserve the joined path when opening the fallback, and derive the
warning's replacement from the actual resolved file so it remains equivalent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]