Fix coverity CIDs: 119845, 107167, 119843, 108158, 108485 and 107460 84/177784/1
authorSaulo Moraes <s.moraes@samsung.com>
Thu, 3 May 2018 16:17:40 +0000 (13:17 -0300)
committerSaulo Aldighieri Moraes <s.moraes@samsung.com>
Thu, 3 May 2018 16:17:40 +0000 (13:17 -0300)
Change-Id: I5f2025fa1ed15c10ae1e6dc6d05276d00fead13a

common/inc/DlpPacketParserResult.h
common/inc/DlpUtils.h
common/src/DlpUtils.cpp
common/src/SocketClient.cpp
server/src/service/DlpPrivacyInfoData.cpp
test/tc-ahocorasick.c
test/tc-dlp-performance.c

index 37cca85..703954e 100644 (file)
 #include <list>
 #include "PrivacyGuardTypes.h"
 
+typedef void * SUB_PARSER_PTR;
 typedef std::list<class DlpPacketParserResult> DlpPacketParserResultList;
 
-#include "DlpUtils.h"
-
 class DlpPacketParserResult
 {
        friend void dlp_ac_search(SUB_PARSER_PTR ptr, const char *data, size_t length, DlpPacketParserResultList &rl);
index c76a5d0..549a0c2 100644 (file)
 #define __DLP_UTILS_H__
 
 #include <string>
-
-typedef void * SUB_PARSER_PTR;
-
+#include <string.h>
+#include <stdio.h>
+#include <pcre.h>
 #include "DlpPacketParserResult.h"
 #include "privacy_guard_client_types.h"
+#include "../../ahocorasick/ahocorasick.h"
 
 //// generic /////////////////////
 /**
index 3d60d52..b807e98 100644 (file)
  * @brief      Utility functions for DLP.
  */
 
-#include <string>
-#include <string.h>
-#include <stdio.h>
 #include "DlpUtils.h"
-#include "DlpPacketParserResult.h"
-#include "privacy_guard_client_types.h"
-#include "../../ahocorasick/ahocorasick.h"
-
-#include <pcre.h>
 
 ////////////////// general ///////////////////////////////
 
index 4963069..2582469 100644 (file)
@@ -56,8 +56,8 @@ int SocketClient::connect()
        int flags;
        if ( (flags = fcntl(m_socketFd, F_GETFL, 0)) == -1 )
                flags = 0;
-       fcntl(m_socketFd, F_SETFL, flags | O_NONBLOCK);
-       TryReturn( m_socketFd != -1, PRIV_GUARD_ERROR_IPC_ERROR, , "fcntl : %s", strerror_r(errno, buf, sizeof(buf)));
+       res = fcntl(m_socketFd, F_SETFL, flags | O_NONBLOCK);
+       TryReturn( res != -1, PRIV_GUARD_ERROR_IPC_ERROR, , "fcntl : %s", strerror_r(errno, buf, sizeof(buf)));
 
        bzero(&remote, sizeof(remote));
        remote.sun_family = AF_UNIX;
index 9bb87e6..b3c3769 100644 (file)
@@ -382,11 +382,10 @@ void
 DlpPrivacyInfoData::loadInfo(const int userId)
 {
        char *ipv4 = NULL, *imei = NULL, *phoneno = NULL, *mac;
-       int ret;
 
        if (m_connection && m_ipv4.empty()) {
-               ret = connection_get_ip_address(m_connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ipv4);
-               if (ret == CONNECTION_ERROR_NONE) {
+               int ret_connection = connection_get_ip_address(m_connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ipv4);
+               if (CONNECTION_ERROR_NONE == ret_connection) {
                        m_ipv4 = ipv4;
                        free(ipv4);
                }
@@ -396,15 +395,15 @@ DlpPrivacyInfoData::loadInfo(const int userId)
        if (m_handle_list.handle == NULL && telephony_init(&m_handle_list) == TELEPHONY_ERROR_NONE) {
                for (unsigned int i = 0; i < m_handle_list.count; i++) {
                        if (waitForModemReady(m_handle_list.handle[i])) {
-                               ret = telephony_modem_get_imei(m_handle_list.handle[i], &imei);
-                               if (ret == TELEPHONY_ERROR_NONE && imei && strlen(imei))
+                               int ret_telephony = telephony_modem_get_imei(m_handle_list.handle[i], &imei);
+                               if (TELEPHONY_ERROR_NONE == ret_telephony && imei && strlen(imei))
                                        m_imei_list.push_back(imei);
                        } else {
                                PG_LOGE("Modem is not ready. IMEI can not be monitored.");
                        }
 
-                       ret = telephony_sim_get_subscriber_number(m_handle_list.handle[i], &phoneno);
-                       if (ret == TELEPHONY_ERROR_NONE && phoneno && strlen(phoneno))
+                       int ret_telephony = telephony_sim_get_subscriber_number(m_handle_list.handle[i], &phoneno);
+                       if (TELEPHONY_ERROR_NONE == ret_telephony && phoneno && strlen(phoneno))
                                m_sim_phoneno_list.insert(phoneno);
 
                        // Tracking SIM status: Phone number may not be available after power up
@@ -425,12 +424,12 @@ DlpPrivacyInfoData::loadInfo(const int userId)
 
        // Loading my profile infos
        if (m_myprofile_watch == false) {
-               ret = contacts_connect();
-               if (ret == CONTACTS_ERROR_NONE) {
+               int ret_contacts = contacts_connect();
+               if (CONTACTS_ERROR_NONE == ret_contacts) {
                        loadMyProfile();
                        m_myprofile_watch = true;
                        contacts_db_add_changed_cb(_contacts_my_profile._uri,
-                                                       myProfileChanged, this);
+                                                                               myProfileChanged, this);
                }
        }
 }
index 52313cb..3792858 100644 (file)
@@ -101,7 +101,7 @@ static void __test_string_match()
        printf("Search match: ");
 
        int awl = 0;
-       char buf[SMATCH_BUFSIZE];
+       char buf[SMATCH_BUFSIZE] = { '\0' };
 
 #ifndef SCENARIO_4
        // load text from file
@@ -117,7 +117,6 @@ static void __test_string_match()
                return;
        }
        close(fd);
-       memset(buf + tsize, 0, 1);
 
        // count words in text
        int nwords = 1;
index 67a3942..7fecff2 100644 (file)
@@ -331,6 +331,7 @@ static void __test_privacy_guard_client_dlp_string_match(int number_of_execution
                if (new_packet_to_send != NULL) {
                        pg_strlcpy(new_packet_to_send, packet_to_send, strlen(packet_to_send));
                        strncat(new_packet_to_send, packet_to_send, sizeof(new_packet_to_send) - strlen(new_packet_to_send) - 1);
+                       free(packet_to_send);
                        packet_to_send = strdup(new_packet_to_send);
                        free(new_packet_to_send);
                }