From 9297cd25765190d1e36a65c9a09fd628d048f4a8 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Tue, 28 Jan 2014 11:44:02 +0200 Subject: [PATCH] Use stringstream and string instead of PATH_MAX --- pdns/arguments.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pdns/arguments.cc b/pdns/arguments.cc index 05d25415db..e526d6f63a 100644 --- a/pdns/arguments.cc +++ b/pdns/arguments.cc @@ -469,7 +469,6 @@ bool ArgvMap::file(const char *fname, bool lax, bool included) struct stat st; DIR *dir; struct dirent *ent; - char namebuf[PATH_MAX] = {0}; // stat if (stat(params["include-dir"].c_str(), &st)) { @@ -492,19 +491,21 @@ bool ArgvMap::file(const char *fname, bool lax, bool included) while((ent = readdir(dir)) != NULL) { if (ent->d_name[0] == '.') continue; // skip any dots if (boost::ends_with(ent->d_name, ".conf")) { + // build name + std::ostringstream namebuf; + namebuf << params["include-dir"].c_str() << "/" << ent->d_name; // FIXME: Use some path separator // ensure it's readable file - snprintf(namebuf, sizeof namebuf, "%s/%s", params["include-dir"].c_str(), ent->d_name); - if (stat(namebuf, &st) || !S_ISREG(st.st_mode)) { - L << Logger::Error << namebuf << " is not a file" << std::endl; - throw ArgException(std::string(namebuf) + " does not exist!"); + if (stat(namebuf.str().c_str(), &st) || !S_ISREG(st.st_mode)) { + L << Logger::Error << namebuf.str() << " is not a file" << std::endl; + throw ArgException(namebuf.str() + " does not exist!"); } - extraConfigs.push_back(std::string(namebuf)); + extraConfigs.push_back(namebuf.str()); } } std::sort(extraConfigs.begin(), extraConfigs.end(), CIStringComparePOSIX()); BOOST_FOREACH(const std::string& fn, extraConfigs) { if (!file(fn.c_str(), lax, true)) { - L << Logger::Error << namebuf << " could not be parsed" << std::endl; + L << Logger::Error << fn << " could not be parsed" << std::endl; throw ArgException(fn + " could not be parsed"); } } -- 2.47.2