From 16efae89925c5cee1a7ae946c036c570f688f852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20P=C3=B6chtrager?= Date: Mon, 24 Jun 2019 13:02:34 +0200 Subject: [PATCH] Fixes for #187 --- wrapper/programs/xcrun.cpp | 18 ++++++++++-------- wrapper/tools.cpp | 9 +++++++-- wrapper/tools.h | 3 ++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/wrapper/programs/xcrun.cpp b/wrapper/programs/xcrun.cpp index 879625f..b51dd93 100644 --- a/wrapper/programs/xcrun.cpp +++ b/wrapper/programs/xcrun.cpp @@ -74,7 +74,7 @@ bool getToolPath(Target &target, std::string &toolpath, const char *tool) { if (!fileExists(toolpath.c_str())) { // Fall back to system executables so 'xcrun git status' etc. works. - if (!isxcodetool && realPath(tool, toolpath)) + if (!isxcodetool && realPath(tool, toolpath, nullptr, nullptr, 0)) return true; err << "xcrun: cannot find '" << tool << "' executable" << err.endl(); @@ -200,14 +200,16 @@ int xcrun(int argc, char **argv, Target &target) { if (getenv("xcrun_log")) showCommand = true; - constexpr const char *ENVVARS[] = { - "DEVELOPER_DIR", "TOOLCHAINS", "xcrun_verbose" - }; + if (!getenv("OSXCROSS_XCRUN_NO_ENV_WARNING")) { + constexpr const char *ENVVARS[] = { + "DEVELOPER_DIR", "TOOLCHAINS", "xcrun_verbose" + }; - for (const char *evar : ENVVARS) { - if (getenv(evar)) { - warn << "xcrun: ignoring environment variable " - << "'" << evar << "'" << warn.endl(); + for (const char *evar : ENVVARS) { + if (getenv(evar)) { + warn << "xcrun: ignoring environment variable " + << "'" << evar << "'" << warn.endl(); + } } } diff --git a/wrapper/tools.cpp b/wrapper/tools.cpp index 6b839a6..d4d0959 100644 --- a/wrapper/tools.cpp +++ b/wrapper/tools.cpp @@ -344,7 +344,8 @@ bool ignoreCCACHE(const char *f, const struct stat &) { } bool realPath(const char *file, std::string &result, - realpathcmp cmp1, realpathcmp cmp2) { + realpathcmp cmp1, realpathcmp cmp2, + const size_t maxSymbolicLinkDepth) { char *PATH = getenv("PATH"); const char *p = PATH ? PATH : ""; struct stat st; @@ -362,6 +363,9 @@ bool realPath(const char *file, std::string &result, result += file; if (!stat(result.c_str(), &st)) { + if (maxSymbolicLinkDepth == 0) + return true; + char buf[PATH_MAX + 1]; if (realpath(result.c_str(), buf)) { @@ -379,6 +383,7 @@ bool realPath(const char *file, std::string &result, else ++pathlen; // PATHDIV + memcpy(path, result.c_str(), pathlen); // not null terminated while ((len = readlink(result.c_str(), buf, PATH_MAX)) != -1) { @@ -390,7 +395,7 @@ bool realPath(const char *file, std::string &result, pathlen = strrchr(buf, PATHDIV) - buf + 1; // + 1: PATHDIV memcpy(path, buf, pathlen); } - if (++n >= 1000) { + if (++n >= maxSymbolicLinkDepth) { err << result << ": too many levels of symbolic links" << err.endl(); result.clear(); diff --git a/wrapper/tools.h b/wrapper/tools.h index 3beba3e..025e62c 100644 --- a/wrapper/tools.h +++ b/wrapper/tools.h @@ -161,7 +161,8 @@ typedef bool (*realpathcmp)(const char *file, const struct stat &st); bool isExecutable(const char *f, const struct stat &); bool ignoreCCACHE(const char *f, const struct stat &); bool realPath(const char *file, std::string &result, - realpathcmp cmp1 = nullptr, realpathcmp cmp2 = nullptr); + realpathcmp cmp1 = nullptr, realpathcmp cmp2 = nullptr, + const size_t maxSymobolicLinkDepth = 1000); bool getPathOfCommand(const char *command, std::string &result, realpathcmp cmp = nullptr);