summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2022-09-05 06:20:24 -0500
committerGitHub <noreply@github.com>2022-09-05 06:20:24 -0500
commite78e2c399fa7daf47fab2a463e798b497943b3b3 (patch)
tree6eb24f20a7c69f3b760d796b74a36632b0857bd9
parent4a7667796b48f75a66424332c8da52fcd5eae45f (diff)
parent3f407aa8d66dacbbf92e22673d8871e429079ce0 (diff)
downloadvyatta-cfg-e78e2c399fa7daf47fab2a463e798b497943b3b3.tar.gz
vyatta-cfg-e78e2c399fa7daf47fab2a463e798b497943b3b3.zip
Merge pull request #50 from jestabro/tag-node-value-name-whitespace
cstore: T4664: add validation: no whitespace in tag node value names
-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 71d30d1..b9f68a2 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,