You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
2.1 KiB

diff -up usbguard-0.7.0/src/Library/ConfigFilePrivate.cpp.strict-config usbguard-0.7.0/src/Library/ConfigFilePrivate.cpp
--- usbguard-0.7.0/src/Library/ConfigFilePrivate.cpp.strict-config 2017-11-03 10:43:09.528657179 +0100
+++ usbguard-0.7.0/src/Library/ConfigFilePrivate.cpp 2017-11-03 11:03:51.338013408 +0100
@@ -23,6 +23,7 @@
#include "ConfigFilePrivate.hpp"
#include "Common/Utility.hpp"
+#include "usbguard/Exception.hpp"
#include "usbguard/Logger.hpp"
#include <stdexcept>
@@ -53,7 +54,7 @@ namespace usbguard
{
_stream.open(path, std::ios::in|std::ios::out);
if (!_stream.is_open()) {
- throw std::runtime_error("Can't open " + path);
+ throw Exception("Configuration", path, "unable to open the configuration file");
}
_dirty = false;
parse();
@@ -62,7 +63,7 @@ namespace usbguard
void ConfigFilePrivate::write()
{
if (!_stream.is_open()) {
- throw std::runtime_error("BUG: ConfigFilePrivate::write: write() before open()");
+ throw USBGUARD_BUG("ConfigFilePrivate::write: write() before open()");
}
if (_dirty) {
@@ -116,21 +117,22 @@ namespace usbguard
while(std::getline(_stream, config_line)) {
++config_line_number;
_lines.push_back(config_line);
+ config_line = trim(config_line);
+
+ if (config_line.size() < 1 || config_line[0] == '#') {
+ continue;
+ }
const size_t nv_separator = config_line.find_first_of("=");
if (nv_separator == std::string::npos) {
- continue;
+ throw Exception("Configuration", "line " + std::to_string(config_line_number), "syntax error");
}
std::string name = trim(config_line.substr(0, nv_separator));
- std::string value = config_line.substr(nv_separator + 1);
-
- if (name[0] == '#') {
- continue;
- }
+ std::string value = trim(config_line.substr(nv_separator + 1));
if (!checkNVPair(name, value)) {
- continue;
+ throw Exception("Configuration", name, "unknown configuration directive");
}
NVPair& setting = _settings[name];