summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsangwan.kwon <sangwan.kwon@samsung.com>2016-06-30 14:54:39 +0900
committersangwan.kwon <sangwan.kwon@samsung.com>2016-06-30 18:16:38 +0900
commit720829a92d86b99bdbebb2de8310b56cdbff802d (patch)
treeb77632e1f7a1ff5d837eccc0bca1d03c338318b1
parentb8ffd7662428b4baff92a0c8271e84c2b55ce47b (diff)
downloadcert-checker-720829a92d86b99bdbebb2de8310b56cdbff802d.tar.gz
cert-checker-720829a92d86b99bdbebb2de8310b56cdbff802d.tar.bz2
cert-checker-720829a92d86b99bdbebb2de8310b56cdbff802d.zip
Fix svace defects
* About taint checking, variable should be checked boundary. * About exception handling, should handle whole possible exception. Change-Id: I6e85bc12cdeea550f7ea1c6dd06b7d9cbb91b3d7 Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
-rw-r--r--src/dpl/core/src/errno_string.cpp1
-rw-r--r--src/ui/popup-bin/popup.cpp167
2 files changed, 97 insertions, 71 deletions
diff --git a/src/dpl/core/src/errno_string.cpp b/src/dpl/core/src/errno_string.cpp
index fa04a45..0770a89 100644
--- a/src/dpl/core/src/errno_string.cpp
+++ b/src/dpl/core/src/errno_string.cpp
@@ -30,7 +30,6 @@
#include <cchecker/dpl/errno_string.h>
#include <cchecker/dpl/assert.h>
#include <cchecker/dpl/exception.h>
-#include <cchecker/dpl/assert.h>
#include <cchecker/dpl/scoped_free.h>
namespace CCHECKER {
diff --git a/src/ui/popup-bin/popup.cpp b/src/ui/popup-bin/popup.cpp
index b3256b1..23003ab 100644
--- a/src/ui/popup-bin/popup.cpp
+++ b/src/ui/popup-bin/popup.cpp
@@ -36,6 +36,11 @@
#include <cchecker/popup-runner.h>
#include <cchecker/dpl/serialization.h>
#include <cchecker/dpl/errno_string.h>
+#include <cchecker/dpl/exception.h>
+
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 1024
+#endif
using namespace CCHECKER::UI;
@@ -204,81 +209,103 @@ void deserialize(cert_checker_popup_data *pdp, char *line, ssize_t line_length)
EAPI_MAIN int
elm_main(int argc, char **argv)
{
- // int pipe_in and int pipe_out should be passed to Popup via args.
- // These parameters should be passed to Popup via pipe_in:
- // std::string app_id
- // std::string pkg_id
- struct cert_checker_popup_data pd;
- struct cert_checker_popup_data *pdp = &pd;
- LogDebug("############################ popup binary ################################");
- setlocale(LC_ALL, "");
-
- if (argc < 3) {
- LogError("To few args passed in exec to popup-bin - should be at least 3:");
- LogError("(binary-name, pipe_in, pipe_out)");
- LogError("return ERROR");
- return popup_status::EXIT_ERROR;
- }
-
- LogDebug("Passed args: " << argv[0] << ", " << argv[1] << ", " << argv[2]);
- int pipe_in;
- int pipe_out;
-
- // Parsing args (pipe_in, pipe_out)
- if (0 == sscanf(argv[1], "%d", &pipe_in)) {
- LogError("Error while parsing pipe_in; return ERROR");
- return popup_status::EXIT_ERROR;
- }
-
- if (0 == sscanf(argv[2], "%d", &pipe_out)) {
- LogError("Error while parsing pipe_out; return ERROR");
- return popup_status::EXIT_ERROR;
- }
-
- LogDebug("Parsed pipes: IN: " << pipe_in << ", OUT: " << pipe_out);
+ try {
+ // int pipe_in and int pipe_out should be passed to Popup via args.
+ // These parameters should be passed to Popup via pipe_in:
+ // std::string app_id
+ // std::string pkg_id
+ struct cert_checker_popup_data pd;
+ struct cert_checker_popup_data *pdp = &pd;
+ LogDebug("############################ popup binary ################################");
+ setlocale(LC_ALL, "");
+
+ if (argc < 3) {
+ LogError("To few args passed in exec to popup-bin - should be at least 3:");
+ LogError("(binary-name, pipe_in, pipe_out)");
+ LogError("return ERROR");
+ return popup_status::EXIT_ERROR;
+ }
+
+ LogDebug("Passed args: " << argv[0] << ", " << argv[1] << ", " << argv[2]);
+ int pipe_in;
+ int pipe_out;
+
+ // Parsing args (pipe_in, pipe_out)
+ if (0 == sscanf(argv[1], "%d", &pipe_in)) {
+ LogError("Error while parsing pipe_in; return ERROR");
+ return popup_status::EXIT_ERROR;
+ }
+
+ if (pipe_in < 0 || pipe_in > FD_SETSIZE) {
+ LogError("fb about pipe_in is in invalid.");
+ return popup_status::EXIT_ERROR;
+ }
+
+ if (0 == sscanf(argv[2], "%d", &pipe_out)) {
+ LogError("Error while parsing pipe_out; return ERROR");
+ return popup_status::EXIT_ERROR;
+ }
+
+ if (pipe_out < 0 || pipe_out > FD_SETSIZE) {
+ LogError("fb about pipe_out is in invalid.");
+ close(pipe_in);
+ return popup_status::EXIT_ERROR;
+ }
+
+ LogDebug("Parsed pipes: IN: " << pipe_in << ", OUT: " << pipe_out);
+
+ if (wait_for_parent_info(pipe_in) == -1) {
+ close(pipe_out);
+ return popup_status::EXIT_ERROR;
+ }
+
+ int buff_size = 1024;
+ char line[buff_size];
+ ssize_t count = 0;
+
+ do {
+ count = TEMP_FAILURE_RETRY(read(pipe_in, line, buff_size));
+ } while (0 == count);
+
+ if (count < 0) {
+ int error = errno;
+ close(pipe_in);
+ close(pipe_out);
+ LogError("read returned a negative value (" << count << ")");
+ LogError("error: " << CCHECKER::GetErrnoString(error));
+ LogError("Exit popup - ERROR");
+ return popup_status::EXIT_ERROR;
+ }
+
+ LogDebug("Read bytes : " << count);
+ close(pipe_in); // cleanup
+ deserialize(pdp, line, count);
+ pdp->result = response_e::RESPONSE_ERROR;
+ show_popup(pdp); // Showing popup
+ // sending validation_result to popup-runner
+ BinaryStream stream_out;
+ LogDebug("pdp->result : " << pdp->result);
+ CCHECKER::Serialization::Serialize(stream_out, pdp->result);
+
+ if (-1 == TEMP_FAILURE_RETRY(write(pipe_out, stream_out.char_pointer(), stream_out.size()))) {
+ LogError("Write to pipe failed!");
+ close(pipe_out);
+ return popup_status::EXIT_ERROR;
+ }
- if (wait_for_parent_info(pipe_in) == -1) {
close(pipe_out);
+ LogDebug("############################ /popup binary ################################");
+ LogDebug("Return: " << popup_status::NO_ERROR);
+ return popup_status::NO_ERROR;
+ } catch (const CCHECKER::Exception &e) {
+ LogError("Exception occured in popup main.");
return popup_status::EXIT_ERROR;
- }
-
- int buff_size = 1024;
- char line[buff_size];
- ssize_t count = 0;
-
- do {
- count = TEMP_FAILURE_RETRY(read(pipe_in, line, buff_size));
- } while (0 == count);
-
- if (count < 0) {
- int error = errno;
- close(pipe_in);
- close(pipe_out);
- LogError("read returned a negative value (" << count << ")");
- LogError("error: " << CCHECKER::GetErrnoString(error));
- LogError("Exit popup - ERROR");
+ } catch (const std::exception &e) {
+ LogError("Exception occured in popup main : " << e.what());
return popup_status::EXIT_ERROR;
- }
-
- LogDebug("Read bytes : " << count);
- close(pipe_in); // cleanup
- deserialize(pdp, line, count);
- pdp->result = response_e::RESPONSE_ERROR;
- show_popup(pdp); // Showing popup
- // sending validation_result to popup-runner
- BinaryStream stream_out;
- LogDebug("pdp->result : " << pdp->result);
- CCHECKER::Serialization::Serialize(stream_out, pdp->result);
-
- if (-1 == TEMP_FAILURE_RETRY(write(pipe_out, stream_out.char_pointer(), stream_out.size()))) {
- LogError("Write to pipe failed!");
- close(pipe_out);
+ } catch (...) {
+ LogError("Unhandled exception occured in popup main.");
return popup_status::EXIT_ERROR;
}
-
- close(pipe_out);
- LogDebug("############################ /popup binary ################################");
- LogDebug("Return: " << popup_status::NO_ERROR);
- return popup_status::NO_ERROR;
}
ELM_MAIN()