From 1876cd482ba9af6a849b21ef374b53b515057624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 8 Jul 2010 12:06:27 +0200 Subject: [PATCH] Suppressions: Validate given id --- lib/settings.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/settings.cpp b/lib/settings.cpp index c37ef784b..d098610a7 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -22,6 +22,7 @@ #include #include #include +#include Settings::Settings() { @@ -71,6 +72,26 @@ bool Settings::Suppressions::parseFile(std::istream &istr) void Settings::Suppressions::addSuppression(const std::string &errorId, const std::string &file, unsigned int line) { + // Check that errorId is valid.. + if (errorId.empty()) + { + std::cerr << "Failed to add suppression. No id." << std::endl; + return; + } + for (std::string::size_type pos = 0; pos < errorId.length(); ++pos) + { + if (errorId[pos] < 0 || !std::isalnum(errorId[pos])) + { + std::cerr << "Failed to add suppression. Invalid id \"" << errorId << "\"" << std::endl; + return; + } + if (pos == 0 && std::isdigit(errorId[pos])) + { + std::cerr << "Failed to add suppression. Invalid id \"" << errorId << "\"" << std::endl; + return; + } + } + _suppressions[errorId][file].push_back(line); _suppressions[errorId][file].sort(); }