summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-01-23 08:13:29 +0100
committerGitHub <noreply@github.com>2023-01-23 08:13:29 +0100
commit3735e38c6e919d6fe059e58d7682562c51dd7afb (patch)
tree3597c756aa8ce277e8fbc39229e72c1efe538e65
parent5ab83d5548b925aac4d0fbbd1e8fb5692f34a5cc (diff)
parent29023638ab3b9da811d23821a651732bd68a2c48 (diff)
downloadvyatta-cfg-3735e38c6e919d6fe059e58d7682562c51dd7afb.tar.gz
vyatta-cfg-3735e38c6e919d6fe059e58d7682562c51dd7afb.zip
Merge pull request #58 from c-po/t4664-backport
cstore: T4664: add validation: no whitespace in tag node value names (backport)
-rw-r--r--src/cstore/cstore.cpp22
-rw-r--r--src/cstore/cstore.hpp4
2 files changed, 26 insertions, 0 deletions
diff --git a/src/cstore/cstore.cpp b/src/cstore/cstore.cpp
index 4750ba0..9dbbc75 100644
--- a/src/cstore/cstore.cpp
+++ b/src/cstore/cstore.cpp
@@ -18,6 +18,7 @@
#include <cstdlib>
#include <cstring>
#include <cstdarg>
+#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -108,6 +109,21 @@ Cstore::createCstore(bool use_edit_level)
return (new unionfs::UnionfsCstore(use_edit_level));
}
+// utility function
+bool
+Cstore::contains_whitespace(const char *name) {
+ int i = 0;
+ char c;
+ while (name[i]) {
+ c = name[i];
+ if (isspace(c)) return true;
+ i++;
+ }
+
+ return false;
+}
+// end utility function
+
// for "specific session" (see UnionfsCstore constructor for details)
Cstore *
Cstore::createCstore(const string& session_id, string& env)
@@ -337,6 +353,7 @@ Cstore::validateSetPath(const Cpath& path_comps)
{
ASSERT_IN_SESSION;
+ Cpath *pcomps = const_cast<Cpath *>(&path_comps);
// if we can get parsed tmpl, path is valid
string terr;
tr1::shared_ptr<Ctemplate> def(get_parsed_tmpl(path_comps, true, terr));
@@ -350,6 +367,11 @@ Cstore::validateSetPath(const Cpath& path_comps)
#else
unique_ptr<SavePaths> save(create_save_paths());
#endif
+ if (def->isTag() && contains_whitespace((*pcomps)[pcomps->size() - 1])) {
+ string output = "Tag node value name must not contain whitespace\n";
+ output_user(output.c_str());
+ return false;
+ }
if (!def->isValue()) {
if (!def->isTypeless()) {
/* disallow setting value node without value
diff --git a/src/cstore/cstore.hpp b/src/cstore/cstore.hpp
index 53d9c53..db37d26 100644
--- a/src/cstore/cstore.hpp
+++ b/src/cstore/cstore.hpp
@@ -444,6 +444,10 @@ private:
};
// end path modifiers
+ // utility function
+ bool contains_whitespace(const char *name);
+ // end utility function
+
// these require full path
// (note: get_parsed_tmpl also uses current tmpl path)
tr1::shared_ptr<Ctemplate> get_parsed_tmpl(const Cpath& path_comps,