From: 이상규/On-Device Lab(SR)/Principal Engineer/삼성전자 Date: Wed, 18 Sep 2019 01:38:08 +0000 (+0900) Subject: [neurun] check null before accessing session (#7536) X-Git-Tag: accepted/tizen/unified/20190918.102349^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2f1aee843584dfb4c5847a1bf6b220aa9de763f3;p=platform%2Fcore%2Fml%2Fnnfw.git [neurun] check null before accessing session (#7536) session will be null-checked before dereferencing. Change-Id: Id8bb2b743eb2079c08ca2522cebca777a60b05b2 Signed-off-by: Sanggyu Lee Signed-off-by: Chunseok Lee --- diff --git a/runtimes/neurun/frontend/api/nnfw_dev.cc b/runtimes/neurun/frontend/api/nnfw_dev.cc index e7ee7a2..ddb6dd5 100644 --- a/runtimes/neurun/frontend/api/nnfw_dev.cc +++ b/runtimes/neurun/frontend/api/nnfw_dev.cc @@ -41,6 +41,13 @@ NNFW_STATUS nnfw_close_session(nnfw_session *session) return NNFW_STATUS_NO_ERROR; } +#define NNFW_RETURN_ERROR_IF_NULL(p) \ + do \ + { \ + if ((p) == NULL) \ + return NNFW_STATUS_ERROR; \ + } while (0) + /* * Load model from nnpackage file or directory * @@ -51,6 +58,7 @@ NNFW_STATUS nnfw_close_session(nnfw_session *session) */ NNFW_STATUS nnfw_load_model_from_file(nnfw_session *session, const char *pacakge_file_path) { + NNFW_RETURN_ERROR_IF_NULL(session); return session->load_model_from_file(pacakge_file_path); } @@ -61,7 +69,11 @@ NNFW_STATUS nnfw_load_model_from_file(nnfw_session *session, const char *pacakge * @param session the session to be prepared * @return NNFW_STATUS_NO_ERROR if successful */ -NNFW_STATUS nnfw_prepare(nnfw_session *session) { return session->prepare(); } +NNFW_STATUS nnfw_prepare(nnfw_session *session) +{ + NNFW_RETURN_ERROR_IF_NULL(session); + return session->prepare(); +} /* * Run inference @@ -69,7 +81,11 @@ NNFW_STATUS nnfw_prepare(nnfw_session *session) { return session->prepare(); } * @param session the session to run inference * @return NNFW_STATUS_NO_ERROR if successful */ -NNFW_STATUS nnfw_run(nnfw_session *session) { return session->run(); } +NNFW_STATUS nnfw_run(nnfw_session *session) +{ + NNFW_RETURN_ERROR_IF_NULL(session); + return session->run(); +} /* * Set input @@ -86,6 +102,7 @@ NNFW_STATUS nnfw_run(nnfw_session *session) { return session->run(); } NNFW_STATUS nnfw_set_input(nnfw_session *session, uint32_t index, NNFW_TYPE type, const void *buffer, size_t length) { + NNFW_RETURN_ERROR_IF_NULL(session); return session->set_input(index, type, buffer, length); } @@ -104,6 +121,7 @@ NNFW_STATUS nnfw_set_input(nnfw_session *session, uint32_t index, NNFW_TYPE type NNFW_STATUS nnfw_set_output(nnfw_session *session, uint32_t index, NNFW_TYPE type, void *buffer, size_t length) { + NNFW_RETURN_ERROR_IF_NULL(session); return session->set_output(index, type, buffer, length); } @@ -118,6 +136,7 @@ NNFW_STATUS nnfw_set_output(nnfw_session *session, uint32_t index, NNFW_TYPE typ NNFW_STATUS nnfw_input_size(nnfw_session *session, uint32_t *number) { + NNFW_RETURN_ERROR_IF_NULL(session); return session->input_size(number); } @@ -131,6 +150,7 @@ NNFW_STATUS nnfw_input_size(nnfw_session *session, uint32_t *number) */ NNFW_STATUS nnfw_output_size(nnfw_session *session, uint32_t *number) { + NNFW_RETURN_ERROR_IF_NULL(session); return session->output_size(number); } @@ -146,6 +166,7 @@ NNFW_STATUS nnfw_output_size(nnfw_session *session, uint32_t *number) NNFW_STATUS nnfw_input_tensorinfo(nnfw_session *session, uint32_t index, nnfw_tensorinfo *tensor_info) { + NNFW_RETURN_ERROR_IF_NULL(session); return session->input_tensorinfo(index, tensor_info); } @@ -161,6 +182,7 @@ NNFW_STATUS nnfw_input_tensorinfo(nnfw_session *session, uint32_t index, NNFW_STATUS nnfw_output_tensorinfo(nnfw_session *session, uint32_t index, nnfw_tensorinfo *tensor_info) { + NNFW_RETURN_ERROR_IF_NULL(session); return session->output_tensorinfo(index, tensor_info); } @@ -174,6 +196,7 @@ NNFW_STATUS nnfw_output_tensorinfo(nnfw_session *session, uint32_t index, NNFW_STATUS nnfw_register_custom_op_info(nnfw_session *session, const char *id, custom_kernel_registration_info *info) { + NNFW_RETURN_ERROR_IF_NULL(session); return session->register_custom_operation(id, info->eval_function); } @@ -185,6 +208,7 @@ NNFW_STATUS nnfw_register_custom_op_info(nnfw_session *session, const char *id, */ NNFW_STATUS nnfw_set_default_backend(nnfw_session *session, const char *backend) { + NNFW_RETURN_ERROR_IF_NULL(session); return session->set_default_backend(backend); } @@ -199,5 +223,6 @@ NNFW_STATUS nnfw_set_default_backend(nnfw_session *session, const char *backend) */ NNFW_STATUS nnfw_set_op_backend(nnfw_session *session, const char *op, const char *backend) { + NNFW_RETURN_ERROR_IF_NULL(session); return session->set_op_backend(op, backend); }