Fix queue msg args buffer size issue 39/95639/1
authorSangyoon Jang <s89.jang@samsung.com>
Thu, 27 Oct 2016 06:30:10 +0000 (15:30 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Fri, 4 Nov 2016 05:14:19 +0000 (14:14 +0900)
Alloc memory for args dynamically.

Change-Id: I7ed8d06477836287a1d994088959c43324c13d80
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
include/pkgmgr-server.h
src/pkgmgr-server.c
src/pm-queue.c

index 13efc58..61b5696 100644 (file)
@@ -90,7 +90,7 @@ typedef struct {
        char pkg_type[MAX_PKG_TYPE_LEN];
        char pkgid[MAX_PKG_NAME_LEN];
        char appid[MAX_PKG_NAME_LEN];
-       char args[MAX_PKG_ARGS_LEN];
+       char *args;
 } pm_dbus_msg;
 
 typedef struct backend_info_t {
@@ -100,7 +100,7 @@ typedef struct backend_info_t {
        char req_id[MAX_REQ_ID_LEN];
        char pkgtype[MAX_PKG_TYPE_LEN];
        char pkgid[MAX_PKG_NAME_LEN];
-       char args[MAX_PKG_ARGS_LEN];
+       char *args;
 } backend_info;
 
 char *_get_backend_cmd(char *type);
index 0986995..72d6cd3 100644 (file)
@@ -1300,7 +1300,9 @@ gboolean queue_job(void *data)
        strncpy(ptr->req_id, item->req_id, MAX_REQ_ID_LEN - 1);
        strncpy(ptr->pkgtype, item->pkg_type, MAX_PKG_TYPE_LEN - 1);
        strncpy(ptr->pkgid, item->pkgid, MAX_PKG_NAME_LEN - 1);
-       strncpy(ptr->args, item->args, MAX_PKG_ARGS_LEN - 1);
+       free(ptr->args);
+       if (item->args)
+               ptr->args = strdup(item->args);
        memset((item->appid), 0, MAX_PKG_NAME_LEN);
        ptr->uid = item->uid;
        ptr->req_type = item->req_type;
index 9ba8be9..7085367 100644 (file)
@@ -279,7 +279,8 @@ int _pm_queue_push(uid_t uid, const char *req_id, int req_type,
        data->msg->uid = uid;
        snprintf(data->msg->pkg_type, sizeof(data->msg->pkg_type), "%s", type);
        snprintf(data->msg->pkgid, sizeof(data->msg->pkgid), "%s", pkgid);
-       snprintf(data->msg->args, sizeof(data->msg->args), "%s", args);
+       if (args)
+               data->msg->args = strdup(args);
 
        data->next = NULL;
 
@@ -330,7 +331,8 @@ pm_dbus_msg *_pm_queue_pop(int position)
        ret->uid = cur->msg->uid;
        snprintf(ret->pkg_type, sizeof(ret->pkg_type), "%s", cur->msg->pkg_type);
        snprintf(ret->pkgid, sizeof(ret->pkgid), "%s", cur->msg->pkgid);
-       snprintf(ret->args, sizeof(ret->args), "%s", cur->msg->args);
+       if (cur->msg->args)
+               ret->args = strdup(cur->msg->args);
 
        ptr->head = cur->next;
        saveptr = ptr->head;
@@ -397,6 +399,7 @@ void _pm_queue_final()
                        prev->next = NULL;
                }
 
+               free(head[c]->msg->args);
                free(head[c]->msg);
                free(head[c]);