Merge browser-provider important MCD patches to SWC code 52/90552/2 accepted/tizen/3.0/mobile/20161015.032412 accepted/tizen/3.0/tv/20161016.003650 accepted/tizen/common/20161007.173341 accepted/tizen/mobile/20161007.104203 accepted/tizen/tv/20161007.104200 submit/tizen_3.0_mobile/20161015.000000 submit/tizen_3.0_tv/20161015.000000 submit/tizen_common/20161007.075531 submit/tizen_mobile/20161007.075524 submit/tizen_tv/20161007.075511
authorVignesh Shanmuga Sunder <vgn.sunder@samsung.com>
Fri, 30 Sep 2016 11:49:32 +0000 (17:19 +0530)
committerHye Kyoung Hwang <cookie@samsung.com>
Fri, 7 Oct 2016 07:43:18 +0000 (00:43 -0700)
Change-Id: I556adfec1447ddb835cda2f89c07f0dc98156144

common-adaptor/common-adaptor-png.c
common-adaptor/common-adaptor.c
provider/browser-provider-db.c
provider/browser-provider-requests-manager.c
provider/browser-provider-tabs.c

index 7021fb33f8d8b750d3cfb39478d997b0e1895807..c8b7aad284eacd51351e36d678ac329e139dbe3d 100755 (executable)
@@ -84,6 +84,12 @@ int bp_common_raw_to_png(const unsigned char *raw_data, int width,
                        PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
                png_set_bgr(png_ptr);
                png_bytep *row_pointers = malloc((size_t)(height * sizeof(png_bytep)));
+               if (row_pointers == NULL){
+                       TRACE_ERROR("malloc failed");
+                       png_destroy_write_struct(&png_ptr, (png_infopp)0);
+                       free(png_buffer);
+                       return -1;
+               }
                int j = 0;
                for (j = 0;j < height; j++)
                        row_pointers[j] = (png_bytep)(raw_data + (j * width * 4));
index c25cf05b498c5ab1f994b1b58f5c215737ce6803..229737a0b53bd37f08f04a594165797b469d77c8 100755 (executable)
 #include <common-adaptor.h>
 #include <browser-provider-socket.h>
 
+// retry count to connect with provider
+#define BP_MAX_RETRY_COUNT 5
+// time in nano seconds approx 300 milli secs.
+#define BP_MAX_RETRY_DELAY 300000000
+
 ///////////// LOCAL APIs //////////////////
 
 static int __adaptor_create_socket()
@@ -169,10 +174,35 @@ int bp_common_adaptor_connect_to_provider(bp_adaptor_defs **adaptorinfo,
                if (bp_ipc_send_custom_type(ipcinfo->cmd_socket, &cmd,
                                sizeof(bp_command_defs)) < 0 ||
                                bp_ipc_send_custom_type(ipcinfo->cmd_socket, &client_type,
-                               sizeof(bp_client_type_defs)) < 0 ||
-                               (errorcode = bp_ipc_read_errorcode(ipcinfo->cmd_socket)) != BP_ERROR_NONE ||
-                               (cid = bp_adaptor_ipc_read_int(ipcinfo->cmd_socket)) <= 0) {
-                       TRACE_ERROR("[CRITICAL] failed to connect with provider");
+                               sizeof(bp_client_type_defs)) < 0) {
+                       TRACE_ERROR("[CRITICAL] failed to send data to provider");
+                       close(ipcinfo->cmd_socket);
+                       free(ipcinfo);
+                       ipcinfo = NULL;
+                       usleep(50000);
+                       return -1;
+               }
+               errorcode = bp_ipc_read_errorcode(ipcinfo->cmd_socket);
+               int retry_count = BP_MAX_RETRY_COUNT;
+               while((errorcode == BP_ERROR_IO_ERROR) && (errno == EINTR || errno == EAGAIN || errno == EINPROGRESS) && retry_count > 0) {
+                       TRACE_ERROR("provider not alive, retry count [%d]", retry_count);
+                       retry_count--;
+                       struct timespec ts;
+                       ts.tv_sec = 0;
+                       ts.tv_nsec = BP_MAX_RETRY_DELAY;
+                       nanosleep(&ts, NULL);
+                       errorcode = bp_ipc_read_errorcode(ipcinfo->cmd_socket);
+               }
+               if (errorcode != BP_ERROR_NONE) {
+                       TRACE_ERROR("[CRITICAL] failed to read errorcode from provider");
+                       close(ipcinfo->cmd_socket);
+                       free(ipcinfo);
+                       ipcinfo = NULL;
+                       usleep(50000);
+                       return -1;
+               }
+               if ((cid = bp_adaptor_ipc_read_int(ipcinfo->cmd_socket)) <= 0) {
+                       TRACE_ERROR("[CRITICAL] failed to read int from provider");
                        close(ipcinfo->cmd_socket);
                        free(ipcinfo);
                        ipcinfo = NULL;
@@ -454,6 +484,10 @@ int bp_common_adaptor_set_blob(const int sock, bp_command_fmt *cmd,
                // check buffer, this code will make crash by overflow
                buffer =
                        (unsigned char *)calloc(byte_length, sizeof(unsigned char));
+               if (buffer == NULL) {
+                       *errorcode = BP_ERROR_INVALID_PARAMETER;
+                       return -1;
+               }
                char *check_buffer = memcpy(buffer, value, byte_length);
                if (check_buffer == NULL) {
                        TRACE_ERROR("[CHECK][%d] buffer:%d", cmd->id, length);
@@ -626,6 +660,12 @@ int bp_common_adaptor_set_blob_shm(const int sock,
                // check buffer, this code will make crash by overflow
                unsigned char *buffer =
                        (unsigned char *)calloc(byte_length, sizeof(unsigned char));
+
+               if (buffer == NULL){
+                       *errorcode = BP_ERROR_INVALID_PARAMETER;
+                       return -1;
+               }
+
                char *check_buffer = memcpy(buffer, value, byte_length);
                if (check_buffer == NULL) {
                        TRACE_ERROR("[CHECK][%d] buffer:%d", cmd->id, length);
index 63031354fa625cdc2f886669fccb06ac2097e233..8cc477b3bb32645ef52563cfaa2a4e074fb0c746 100755 (executable)
@@ -1893,6 +1893,11 @@ int bp_db_backup(sqlite3 *handle, char *path)
        if (errorcode == SQLITE_OK) {
                pbackup =
                        sqlite3_backup_init(backup_handle, "main", handle, "main");
+               if (pbackup == NULL) {
+                       sqlite3_close(backup_handle);
+                       TRACE_ERROR("[INIT]");
+                       return -1;
+               }
                do {
                        errorcode = sqlite3_backup_step(pbackup, -1);
                        TRACE_SECURE_INFO("progress (%d)",
@@ -1930,6 +1935,11 @@ int bp_db_restore(sqlite3 *handle, char *path)
        if (errorcode == SQLITE_OK) {
                pbackup =
                        sqlite3_backup_init(handle, "main", backup_handle, "main");
+               if (pbackup == NULL) {
+                       sqlite3_close(backup_handle);
+                       TRACE_ERROR("[INIT]");
+                       return -1;
+               }
                do {
                        errorcode = sqlite3_backup_step(pbackup, -1);
                        TRACE_SECURE_INFO("progress (%d)",
@@ -1958,9 +1968,13 @@ char *bp_db_get_text_stmt(sqlite3_stmt* stmt, int index)
        if (getbytes > 0) {
                getstr = (char *)calloc(getbytes + 1, sizeof(char));
                if (getstr != NULL) {
-                       memcpy(getstr, sqlite3_column_text(stmt, index),
-                               getbytes * sizeof(char));
-                       getstr[getbytes] = '\0';
+                       char *gettext = NULL;
+                       gettext = sqlite3_column_text(stmt, index);
+                       if (gettext != NULL){
+                               memcpy(getstr, gettext,
+                                               getbytes * sizeof(char));
+                               getstr[getbytes] = '\0';
+                       }
                } else {
                        TRACE_ERROR("[CHECK] alloc for string");
                }
index f81f55311d2bbd0fa7dbe099cb8e9c69c2b3abd9..b6d365e0bbbe55067206a29e5a062c0976dd6918 100755 (executable)
@@ -505,7 +505,7 @@ void bp_thread_requests_manager(bp_privates_defs *privates)
        fd_set rset, eset, listen_fdset, except_fdset;
        struct timeval timeout; // for timeout of select
        long flexible_timeout = BP_CARE_CLIENT_MAX_INTERVAL;
-       int listenfd, clientfd, maxfd;
+       int listenfd, maxfd;
        socklen_t clientlen;
        struct sockaddr_un clientaddr;
        unsigned i, is_timeout;
@@ -545,7 +545,6 @@ void bp_thread_requests_manager(bp_privates_defs *privates)
                // initialize timeout structure for calling timeout exactly
                memset(&timeout, 0x00, sizeof(struct timeval));
                timeout.tv_sec = flexible_timeout;
-               clientfd = -1;
                is_timeout = 1;
 
                rset = listen_fdset;
@@ -572,7 +571,7 @@ void bp_thread_requests_manager(bp_privates_defs *privates)
 
                        // Anyway accept client.
                        clientlen = sizeof(clientaddr);
-                       clientfd = accept(listenfd, (struct sockaddr *)&clientaddr,
+                       int clientfd = accept(listenfd, (struct sockaddr *)&clientaddr,
                                                        &clientlen);
                        if (clientfd < 0) {
                                TRACE_ERROR("[CRITICAL] accept provider was crashed ?");
@@ -823,6 +822,9 @@ void bp_thread_requests_manager(bp_privates_defs *privates)
                                bp_ipc_send_custom_type(clientfd,
                                        &privates->slots[i].client->cid, sizeof(int));
 
+                       } else {
+                               //Unknown case
+                               close(clientfd);
                        }
                } // New Connection
 
index e1ca68e66a1b1460518492d2864f55212ab7c326..dc7dd0331fe3dae85b3e7f6acff9b64fff5b066d 100755 (executable)
@@ -255,32 +255,38 @@ static bp_error_defs __bp_tab_get_info_offset(int sock, int id, bp_shm_defs *shm
                columns_index = 0;
                if (offset & BP_TAB_O_INDEX) {
                        int *recvint = columns[columns_index].value;
-                       info.index = *recvint;
+                       if (recvint != NULL)
+                               info.index = *recvint;
                        columns_index++;
                }
                if (offset & BP_TAB_O_IS_ACTIVATED) {
                        int *recvint = columns[columns_index].value;
-                       info.is_activated = *recvint;
+                       if (recvint != NULL)
+                               info.is_activated = *recvint;
                        columns_index++;
                }
                if (offset & BP_TAB_O_IS_INCOGNITO) {
                        int *recvint = columns[columns_index].value;
-                       info.is_incognito = *recvint;
+                       if (recvint != NULL)
+                               info.is_incognito = *recvint;
                        columns_index++;
                }
                if (offset & BP_TAB_O_BROWSER_INSTANCE) {
                        int *recvint = columns[columns_index].value;
-                       info.browser_instance = *recvint;
+                       if (recvint != NULL)
+                               info.browser_instance = *recvint;
                        columns_index++;
                }
                if (offset & BP_TAB_O_DATE_CREATED) {
                        int *recvint = columns[columns_index].value;
-                       info.date_created = *recvint;
+                       if (recvint != NULL)
+                               info.date_created = *recvint;
                        columns_index++;
                }
                if (offset & BP_TAB_O_DATE_MODIFIED) {
                        int *recvint = columns[columns_index].value;
-                       info.date_modified = *recvint;
+                       if (recvint != NULL)
+                               info.date_modified = *recvint;
                        columns_index++;
                }
 
@@ -438,7 +444,7 @@ static bp_error_defs __bp_tab_activate(int sock, int id)
                        BP_DB_COMMON_COL_DEVICE_ID, BP_DB_COL_TYPE_TEXT,
                        device_id, &errorcode);
        TRACE_SECURE_DEBUG("[%d] current activated:%d device-id:%s", id,
-           activated_id, device_id);
+                       activated_id, device_id);
        free(device_id);
        if (activated_id == id) {
                TRACE_ERROR("[ACTIVATE][%d] already activated", id);