From 47e0ee602cb3a6fa9dfe19e1b55f1bae868a1bad Mon Sep 17 00:00:00 2001 From: Bjoern Sikora Date: Fri, 25 Jun 2010 11:27:49 +0200 Subject: [PATCH] Escaped argument for external warning log. --- src/logger.cpp | 24 ++++++++++++++++++++++++ src/logger.hpp | 2 ++ 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/src/logger.cpp b/src/logger.cpp index 7b4fd58..3dc2486 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -82,6 +82,28 @@ void Logger::log_notice(const string& msg) const /** +* Escape shell arguments. +* @param input The input to escape. +* @return The escaped string ready to use for the shell. +*/ +string Logger::escape_shellarg(const string &input) +{ + string output = "'"; + string::const_iterator it, it_end = input.end(); + for (it = input.begin(); it != it_end; it++) + { + if ( (*it) == '\'') + output += "'\\'"; + + output += *it; + } + + output += "'"; + return output; +} + + +/** * Decides if Logging through syslog if enabled or through std. * @param msg The message to log. */ @@ -99,6 +121,8 @@ void Logger::log_warning(const string& msg, int level) if (!message.empty() && message[message.length()-1] == '\n') message.erase(message.length()-1); /*lint !e534 */ + message = escape_shellarg(message); + string external = ExternalWarningLog; external.append(" "); external.append("\""); diff --git a/src/logger.hpp b/src/logger.hpp index d5ae694..d3c82ec 100644 --- a/src/logger.hpp +++ b/src/logger.hpp @@ -42,6 +42,8 @@ public: void clear_external_send_messages(); + std::string escape_shellarg(const std::string &input); + void log_notice(const std::string& msg) const; void log_warning(const std::string& msg, int loglevel); -- 1.7.1