[SATIZENVUL-1315/SATIZENVUL-1316] Remove msg size from thumbMsg 96/169496/3
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 7 Feb 2018 05:49:06 +0000 (14:49 +0900)
committerMinje ahn <minje.ahn@samsung.com>
Thu, 8 Feb 2018 07:33:17 +0000 (07:33 +0000)
Change-Id: Ie1c283ba31e3c627e8eaec3cf16ec23dddb90de6
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
lib/include/media-server-ipc.h
lib/media-util-cynara.c
src/server/media-server-thumb.c

index 499ae87..3dd7a50 100755 (executable)
@@ -102,8 +102,6 @@ typedef struct _thumbMsg {
        int thumb_size;
        int thumb_width;
        int thumb_height;
-       int origin_path_size;
-       int dest_path_size;
        unsigned char *thumb_data;
        char org_path[MAX_FILEPATH_LEN];
        char dst_path[MAX_FILEPATH_LEN];
index d47a55c..a9602b1 100755 (executable)
@@ -143,7 +143,7 @@ int ms_cynara_receive_untrusted_message_thumb(int sockfd, thumbMsg *recv_msg, ms
        if (!recv_msg || !credentials)
                return MS_MEDIA_ERR_INVALID_PARAMETER;
 
-       header_size = sizeof(thumbMsg) -(MAX_FILEPATH_LEN * 2) - sizeof(unsigned char *);
+       header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
        MS_MALLOC(buf, header_size);
 
        if ((recv_msg_size = recv(sockfd, buf, header_size, 0)) < 0) {
@@ -161,58 +161,6 @@ int ms_cynara_receive_untrusted_message_thumb(int sockfd, thumbMsg *recv_msg, ms
        memcpy(recv_msg, buf, header_size);
        MS_SAFE_FREE(buf);
 
-       if (recv_msg->origin_path_size <= 0) {
-               MSAPI_DBG_ERR("msg->origin_path_size is invalid %d", recv_msg->origin_path_size);
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       MS_MALLOC(buf, (unsigned int)(recv_msg->origin_path_size));
-       if (buf == NULL) {
-               MSAPI_DBG_STRERROR("malloc failed");
-               return MS_MEDIA_ERR_OUT_OF_MEMORY;
-       }
-
-       if ((recv_msg_size = recv(sockfd, buf, recv_msg->origin_path_size, 0)) < 0) {
-               MS_SAFE_FREE(buf);
-               if (errno == EWOULDBLOCK) {
-                       MSAPI_DBG_ERR("Timeout. Can't try any more");
-                       return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
-               } else {
-                       MSAPI_DBG_ERR("recv failed");
-                       return MS_MEDIA_ERR_SOCKET_RECEIVE;
-               }
-
-       }
-
-       SAFE_STRLCPY(recv_msg->org_path, (char*)buf, sizeof(recv_msg->org_path));
-       MS_SAFE_FREE(buf);
-
-       if (recv_msg->dest_path_size <= 0) {
-               MSAPI_DBG_ERR("msg->origin_path_size is invalid %d", recv_msg->dest_path_size);
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       MS_MALLOC(buf, (unsigned int)(recv_msg->dest_path_size));
-       if (buf == NULL) {
-               MSAPI_DBG_STRERROR("malloc failed");
-               return MS_MEDIA_ERR_OUT_OF_MEMORY;
-       }
-
-       if ((recv_msg_size = recv(sockfd, buf, recv_msg->dest_path_size, 0)) < 0) {
-               MS_SAFE_FREE(buf);
-               if (errno == EWOULDBLOCK) {
-                       MSAPI_DBG_ERR("Timeout. Can't try any more");
-                       return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT;
-               } else {
-                       MSAPI_DBG_ERR("recv failed");
-                       return MS_MEDIA_ERR_SOCKET_RECEIVE;
-               }
-
-       }
-
-       SAFE_STRLCPY(recv_msg->dst_path, (char*)buf, sizeof(recv_msg->dst_path));
-       MS_SAFE_FREE(buf);
-
        ret = cynara_creds_socket_get_pid(sockfd, &(credentials->pid));
        MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "[CYNARA]Failed to get pid");
 
index 7127239..1e1dd37 100755 (executable)
@@ -116,7 +116,7 @@ int _ms_thumb_recv_msg(int sock, thumbMsg *msg)
 
        unsigned int header_size = 0;
 
-       header_size = sizeof(thumbMsg) -(MAX_FILEPATH_LEN * 2) - sizeof(unsigned char *);
+       header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
 
        MS_MALLOC(buf, header_size);
        if (buf == NULL) {
@@ -131,7 +131,7 @@ int _ms_thumb_recv_msg(int sock, thumbMsg *msg)
        }
        memcpy(msg, buf, header_size);
 
-       MS_DBG("origin_path_size : %d, dest_path_size : %d, thumb_size : %d, status : %d", msg->origin_path_size, msg->dest_path_size, msg->thumb_size, msg->status);
+       MS_DBG("status[%d]", msg->status);
 
        MS_SAFE_FREE(buf);
 
@@ -140,71 +140,67 @@ int _ms_thumb_recv_msg(int sock, thumbMsg *msg)
                return MS_MEDIA_ERR_NONE;
        }
 
-       MS_MALLOC(block_buf, MS_SOCK_BLOCK_SIZE);
-
-       remain_size = msg->origin_path_size + msg->dest_path_size + msg->thumb_size;
-       MS_MALLOC(buf, remain_size);
-       if (buf == NULL) {
-               MS_SAFE_FREE(block_buf);
-               return MS_MEDIA_ERR_OUT_OF_MEMORY;
-       }
-
-       while (remain_size > 0) {
-               if (remain_size < MS_SOCK_BLOCK_SIZE)
-                       block_size = remain_size;
-
-               if ((recv_msg_len = recv(sock, block_buf, block_size, 0)) < 0) {
-                       MS_DBG_STRERROR("recv failed");
-                       MS_SAFE_FREE(buf);
-                       MS_SAFE_FREE(block_buf);
-                       return _media_thumb_get_error();
-               }
-               memcpy(buf+recv_block, block_buf, block_size);
-               recv_block += block_size;
-               remain_size -= block_size;
-               memset(block_buf, 0, MS_SOCK_BLOCK_SIZE);
-       }
-
-       MS_SAFE_FREE(block_buf);
-
-       if (msg->origin_path_size <= 0 || msg->origin_path_size > MS_FILE_PATH_LEN_MAX) {
-               MS_SAFE_FREE(buf);
-               MS_DBG_ERR("msg->origin_path_size is invalid %d", msg->origin_path_size);
+       if (strlen(msg->org_path) == 0 || strlen(msg->org_path) > MS_FILE_PATH_LEN_MAX) {
+               MS_DBG_ERR("org_path size is invalid %d", strlen(msg->org_path));
 
                return MS_MEDIA_ERR_DATA_TAINTED;
        }
 
-       SAFE_STRLCPY(msg->org_path, (char*)buf, sizeof(msg->org_path));
-
-       if (msg->dest_path_size <= 0 || msg->dest_path_size > MS_FILE_PATH_LEN_MAX) {
-               MS_SAFE_FREE(buf);
-               MS_DBG_ERR("msg->dest_path_size is invalid %d", msg->dest_path_size);
+       /* it can be empty string */
+       if (strlen(msg->dst_path) > MS_FILE_PATH_LEN_MAX) {
+               MS_DBG_ERR("dst_path size is invalid %d", strlen(msg->dst_path));
 
                return MS_MEDIA_ERR_DATA_TAINTED;
        }
 
-       SAFE_STRLCPY(msg->dst_path, (char *)buf + msg->origin_path_size, sizeof(msg->dst_path));
-
-       MS_SAFE_FREE(msg->thumb_data);
-
        if (msg->thumb_size < 0) {
-               MS_SAFE_FREE(buf);
                MS_DBG_ERR("msg->thumb_size is invalid %d", msg->thumb_size);
                return MS_MEDIA_ERR_DATA_TAINTED;
        }
 
        if (msg->thumb_size > 0) {
+               remain_size = msg->thumb_size;
+               MS_MALLOC(block_buf, MS_SOCK_BLOCK_SIZE);
+               if (block_buf == NULL) {
+                       return MS_MEDIA_ERR_OUT_OF_MEMORY;
+               }
+
+               MS_MALLOC(buf, remain_size);
+               if (buf == NULL) {
+                       MS_SAFE_FREE(block_buf);
+                       return MS_MEDIA_ERR_OUT_OF_MEMORY;
+               }
+
+               while (remain_size > 0) {
+                       if (remain_size < MS_SOCK_BLOCK_SIZE)
+                               block_size = remain_size;
+
+                       if ((recv_msg_len = recv(sock, block_buf, block_size, 0)) < 0) {
+                               MS_DBG_STRERROR("recv failed");
+                               MS_SAFE_FREE(buf);
+                               MS_SAFE_FREE(block_buf);
+                               return _media_thumb_get_error();
+                       }
+                       memcpy(buf+recv_block, block_buf, block_size);
+                       recv_block += block_size;
+                       remain_size -= block_size;
+                       memset(block_buf, 0, MS_SOCK_BLOCK_SIZE);
+               }
+
+               MS_SAFE_FREE(block_buf);
+               MS_SAFE_FREE(msg->thumb_data);
+
                MS_MALLOC(msg->thumb_data, (unsigned int)(msg->thumb_size));
                if (msg->thumb_data != NULL) {
-                       memcpy(msg->thumb_data, buf + msg->origin_path_size + msg->dest_path_size, msg->thumb_size);
+                       memcpy(msg->thumb_data, buf, msg->thumb_size);
                } else {
                        MS_SAFE_FREE(buf);
 
                        return MS_MEDIA_ERR_OUT_OF_MEMORY;
                }
-       }
 
-       MS_SAFE_FREE(buf);
+               MS_SAFE_FREE(buf);
+       }
 
        return MS_MEDIA_ERR_NONE;
 }
@@ -214,24 +210,20 @@ int _ms_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
        if (req_msg == NULL || buf == NULL)
                return -1;
 
-       int org_path_len = 0;
-       int dst_path_len = 0;
        int data_len = 0;
        int header_size = 0;
        unsigned int size = 0;
 
-       header_size = sizeof(thumbMsg) -(MAX_FILEPATH_LEN * 2) - sizeof(unsigned char *);
-       org_path_len = req_msg->origin_path_size;
-       dst_path_len = req_msg->dest_path_size;
+       header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
        data_len = req_msg->thumb_size;
-       if ((org_path_len < 0 || org_path_len > MAX_FILEPATH_LEN) || (dst_path_len < 0 || dst_path_len > MAX_FILEPATH_LEN) || data_len < 0) {
+       if (data_len < 0) {
                MS_DBG_ERR("msg size is wrong");
                return -1;
        }
 
-       MS_DBG_SLOG("Basic Size : %d, org_path : %s[%d], dst_path : %s[%d], thumb_data : %d", header_size, req_msg->org_path, org_path_len, req_msg->dst_path, dst_path_len, req_msg->thumb_size);
+       MS_DBG_SLOG("Basic Size[%d] org_path[%s] dst_path[%s] thumb_data[%d]", header_size, req_msg->org_path, req_msg->dst_path, req_msg->thumb_size);
 
-       size = header_size + org_path_len + dst_path_len + data_len;
+       size = header_size + data_len;
        MS_MALLOC(*buf, size);
        if (*buf == NULL) {
                MS_DBG_STRERROR("MALLOC failed");
@@ -239,10 +231,8 @@ int _ms_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_size)
        }
 
        memcpy(*buf, req_msg, header_size);
-       memcpy((*buf)+header_size, req_msg->org_path, org_path_len);
-       memcpy((*buf)+header_size + org_path_len, req_msg->dst_path, dst_path_len);
        if (data_len > 0)
-               memcpy((*buf)+header_size + org_path_len + dst_path_len, req_msg->thumb_data, data_len);
+               memcpy((*buf) + header_size, req_msg->thumb_data, data_len);
 
        *buf_size = size;
 
@@ -380,9 +370,7 @@ gboolean _ms_thumb_agent_timer()
 
                msg.msg_type = THUMB_REQUEST_KILL_SERVER;
                msg.org_path[0] = '\0';
-               msg.origin_path_size = 1;
                msg.dst_path[0] = '\0';
-               msg.dest_path_size = 1;
                msg.thumb_size = 0;
 
                /* Command Kill to thumbnail server */
@@ -466,12 +454,10 @@ gboolean _ms_thumb_request_to_server(gpointer data)
 
                        res_msg.msg_type = THUMB_RESPONSE;
                        res_msg.status = MS_MEDIA_ERR_INTERNAL;
-                       res_msg.origin_path_size = strlen(recv_msg->org_path);
                        SAFE_STRLCPY(res_msg.org_path, recv_msg->org_path, sizeof(res_msg.org_path));
                        res_msg.dst_path[0] = '\0';
-                       res_msg.dest_path_size = 1;
-                       res_msg.thumb_data = (unsigned char *)"\0";
-                       res_msg.thumb_size = 1;
+                       res_msg.thumb_data = NULL;
+                       res_msg.thumb_size = 0;
 
                        int buf_size = 0;
                        unsigned char *buf = NULL;
@@ -495,12 +481,10 @@ gboolean _ms_thumb_request_to_server(gpointer data)
        }
 
        SAFE_STRLCPY(res_msg.org_path, recv_msg->org_path, sizeof(res_msg.org_path));
-       res_msg.origin_path_size = recv_msg->origin_path_size;
-       res_msg.dest_path_size = strlen(res_msg.dst_path) + 1;
 
        int buf_size = 0;
        int sending_block = 0;
-       int block_size = sizeof(res_msg) - MAX_FILEPATH_LEN*2 - sizeof(unsigned char *);
+       int block_size = sizeof(res_msg) - sizeof(unsigned char *);
        unsigned char *buf = NULL;
        _ms_thumb_set_buffer(&res_msg, &buf, &buf_size);
 
@@ -595,10 +579,8 @@ gboolean _ms_thumb_agent_read_socket(GIOChannel *src,
 
                res_msg.msg_type = THUMB_RESPONSE;
                res_msg.status = MS_MEDIA_ERR_INTERNAL;
-               res_msg.origin_path_size = recv_msg->origin_path_size;
                SAFE_STRLCPY(res_msg.org_path, recv_msg->org_path, sizeof(res_msg.org_path));
                res_msg.dst_path[0] = '\0';
-               res_msg.dest_path_size = 1;
                res_msg.thumb_size = 0;
 
                int buf_size = 0;