summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author이춘석/On-Device Lab(SR)/Staff Engineer/삼성전자 <chunseok.lee@samsung.com>2019-09-17 09:53:09 (GMT)
committerGitHub Enterprise <noreply-CODE@samsung.com>2019-09-17 09:53:09 (GMT)
commit3c4f2e5ed17a169bd9d5759b2d5a88f2e92b51a1 (patch)
tree78f7783a09ac67d91f6b043c23a08337ab55e8f5
parentae69900a8899873979a84efe423ccea3323a8b99 (diff)
downloadnnfw-3c4f2e5ed17a169bd9d5759b2d5a88f2e92b51a1.zip
nnfw-3c4f2e5ed17a169bd9d5759b2d5a88f2e92b51a1.tar.gz
nnfw-3c4f2e5ed17a169bd9d5759b2d5a88f2e92b51a1.tar.bz2
Null-terminating check for backend conf api (#7516)
* Null-terminating check for backend conf api - Add null terminaing function - Add check routine Signed-off-by: Chunseok Lee <chunseok.lee@samsung.com> * Give name to arg max length in backend conf - Add macro for max length - 32 for backend name, 64 for op name * fix format * add null check * add null check to nnfw_set_op_backend * Check null inside nnfw_session
-rw-r--r--runtimes/neurun/frontend/api/wrapper/nnfw_api.cc35
-rw-r--r--runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp4
2 files changed, 34 insertions, 5 deletions
diff --git a/runtimes/neurun/frontend/api/wrapper/nnfw_api.cc b/runtimes/neurun/frontend/api/wrapper/nnfw_api.cc
index 80a768e..a6021f0 100644
--- a/runtimes/neurun/frontend/api/wrapper/nnfw_api.cc
+++ b/runtimes/neurun/frontend/api/wrapper/nnfw_api.cc
@@ -27,6 +27,25 @@
#include <stdint.h>
#include <util/ConfigSource.h>
+/*
+ * API does not accept string argument longer than max length below
+ */
+#define MAX_BACKEND_NAME_LENGTH 32
+#define MAX_OP_NAME_LENGTH 64
+
+// Is null-terminating in length ?
+static bool null_terminating(const char *str, uint32_t length)
+{
+ for (uint32_t i = 0; i < length; i++)
+ {
+ if (*(str + i) == '\0')
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
nnfw_session::nnfw_session()
: _graph{nullptr}, _execution{nullptr},
_kernel_registry{std::make_shared<neurun::backend::custom::KernelRegistry>()},
@@ -300,10 +319,15 @@ static std::string get_op_backend_string(std::string op)
}
}
-NNFW_STATUS nnfw_session::set_default_backend(std::string backend)
+NNFW_STATUS nnfw_session::set_default_backend(const char *backend)
{
try
{
+ if (!backend || null_terminating(backend, MAX_BACKEND_NAME_LENGTH) == false)
+ {
+ return NNFW_STATUS_ERROR;
+ }
+
_source->set("OP_BACKEND_ALLOPS", backend);
}
catch (...)
@@ -314,11 +338,16 @@ NNFW_STATUS nnfw_session::set_default_backend(std::string backend)
return NNFW_STATUS_NO_ERROR;
}
-NNFW_STATUS nnfw_session::set_op_backend(std::string op, std::string backend)
+NNFW_STATUS nnfw_session::set_op_backend(const char *op, const char *backend)
{
-
try
{
+ if (!op || !null_terminating(op, MAX_OP_NAME_LENGTH) || !backend ||
+ !null_terminating(backend, MAX_BACKEND_NAME_LENGTH))
+ {
+ return NNFW_STATUS_ERROR;
+ }
+
auto key = get_op_backend_string(op);
if (key.empty())
diff --git a/runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp b/runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp
index 5b44650..8451416 100644
--- a/runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp
+++ b/runtimes/neurun/frontend/api/wrapper/nnfw_api.hpp
@@ -64,8 +64,8 @@ public:
NNFW_STATUS register_custom_operation(const std::string &id, nnfw_custom_eval eval_func);
- NNFW_STATUS set_default_backend(std::string backend);
- NNFW_STATUS set_op_backend(std::string op, std::string backend);
+ NNFW_STATUS set_default_backend(const char *backend);
+ NNFW_STATUS set_op_backend(const char *op, const char *backend);
private:
std::shared_ptr<neurun::graph::Graph> _graph;