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 37cca85928f43e6dd9df5603f03fe7df22cefc4c..703954e6c19f1ee86886e2ea599eceed04e0f005 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 c76a5d076725620ebb2e173d7e2f38dc1cb0de9e..549a0c2a0c67df5d74f82e4b501e565d3ce179c7 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 3d60d5279ff0ed5af4f22ee51c3a8cc0a555e33c..b807e98693eaca36163b3f6dec28dc580eb68108 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 496306928e52365ef0e92d18096eb6a08830dbca..2582469e10fbc513ce81b44f99c6691110608a43 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 9bb87e6e8f95e482a7994c28377f4a7a57700691..b3c3769c5081f549c6d541bb52c23d30a1b9cb6f 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 52313cb585a064017afdcb1e26b0ea74df8d8874..3792858a6bc483890d1ae3267d52af4b968c49dd 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 67a39429ec977a5f23e5180c346ad861e855b932..7fecff2803d10d4a80d09a74f27da6df65bbd33c 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);
                }