Skip to content

Commit

Permalink
(FACT-1373) Prevent fact calls from external facts
Browse files Browse the repository at this point in the history
Prior to this commit, it was possible to make a facter call from
within an external fact. This would result in a fork bomb where
facter would be constantly calling into itself. In order to prevent
this, set an environment variable that allows us to ensure facter
is not already running when we make the call to evaluate external
facts.
  • Loading branch information
HAIL9000 committed May 9, 2016
1 parent be447f8 commit 9f03658
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions exe/facter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <facter/logging/logging.hpp>
#include <facter/facts/collection.hpp>
#include <facter/ruby/ruby.hpp>
#include <leatherman/logging/logging.hpp>
#include <leatherman/util/environment.hpp>
#include <leatherman/util/scope_exit.hpp>
#include <boost/algorithm/string.hpp>
// Note the caveats in nowide::cout/cerr; they're not synchronized with stdio.
Expand All @@ -25,8 +27,10 @@
using namespace std;
using namespace facter::facts;
using namespace facter::logging;
using leatherman::util::environment;
namespace po = boost::program_options;


void help(po::options_description& desc)
{
boost::nowide::cout <<
Expand Down Expand Up @@ -251,7 +255,15 @@ int main(int argc, char **argv)
facts.add_default_facts(ruby);

if (!vm.count("no-external-facts")) {
string inside_facter;
environment::get("INSIDE_FACTER", inside_facter);

if (inside_facter == "true") {
LOG_WARNING("Facter was called recursively, skipping external facts. Add '--no-external-facts' to silence this warning");
} else {
environment::set("INSIDE_FACTER", "true");
facts.add_external_facts(external_directories);
}
}

// Add the environment facts
Expand Down

0 comments on commit 9f03658

Please sign in to comment.