[FIX] check_pf_by_comm() 48/39748/2
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 21 May 2015 18:31:10 +0000 (21:31 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 21 May 2015 18:48:14 +0000 (21:48 +0300)
Change-Id: Ic8b1ea648daf8d80c435797aa8331b4eb4358530
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
us_manager/pf/pf_group.c
us_manager/pf/proc_filters.c
us_manager/pf/proc_filters.h

index cc1fa79..9b3e7e3 100644 (file)
@@ -305,6 +305,7 @@ EXPORT_SYMBOL_GPL(get_pf_group_by_tgid);
  */
 struct pf_group *get_pf_group_by_comm(char *comm, void *priv)
 {
+       int ret;
        struct pf_group *pfg;
 
        list_for_each_entry(pfg, &pfg_list, list) {
@@ -316,7 +317,12 @@ struct pf_group *get_pf_group_by_comm(char *comm, void *priv)
        if (pfg == NULL)
                return NULL;
 
-       set_pf_by_comm(&pfg->filter, comm, priv);
+       ret = set_pf_by_comm(&pfg->filter, comm, priv);
+       if (ret) {
+               printk(KERN_ERR "ERROR: set_pf_by_comm, ret=%d\n", ret);
+               free_pfg(pfg);
+               return NULL;
+       }
 
        add_pfg_by_list(pfg);
 
index 64b94d7..ee9cf4c 100644 (file)
@@ -144,17 +144,25 @@ void set_pf_by_tgid(struct proc_filter *pf, pid_t tgid, void *priv)
  * @param pf Pointer to the proc_filter struct
  * @param comm Task comm
  * @param priv Private data
- * @return Void
+ * @return 0 on suceess, error code on error.
  */
-void set_pf_by_comm(struct proc_filter *pf, char *comm, void *priv)
+int set_pf_by_comm(struct proc_filter *pf, char *comm, void *priv)
 {
        size_t len = strnlen(comm, TASK_COMM_LEN);
+       char *new_comm = kmalloc(len, GFP_KERNEL);
+
+       if (new_comm == NULL)
+               return -ENOMEM;
+
+       /* copy comm */
+       memcpy(new_comm, comm, len - 1);
+       new_comm[len - 1] = '\0';
 
        pf->call = &call_by_comm;
-       pf->data = kmalloc(len, GFP_KERNEL);
-       memset(pf->data, 0, len);
-       memcpy(pf->data, comm, len - 1);
+       pf->data = new_comm;
        pf->priv = priv;
+
+       return 0;
 }
 
 /**
@@ -228,7 +236,7 @@ int check_pf_by_tgid(struct proc_filter *filter, pid_t tgid)
 int check_pf_by_comm(struct proc_filter *filter, char *comm)
 {
        return ((filter->call == &call_by_comm) && (filter->data != NULL) &&
-               (!strncmp(filter->data, comm, TASK_COMM_LEN)));
+               (!strncmp(filter->data, comm, TASK_COMM_LEN - 1)));
 }
 
 /**
index 26fe9c3..fe96276 100644 (file)
@@ -54,7 +54,7 @@ struct proc_filter {
 void set_pf_by_dentry(struct proc_filter *pf, struct dentry *dentry,
                      void *priv);
 void set_pf_by_tgid(struct proc_filter *pf, pid_t tgid, void *priv);
-void set_pf_by_comm(struct proc_filter *pf, char *comm, void *priv);
+int set_pf_by_comm(struct proc_filter *pf, char *comm, void *priv);
 void set_pf_dumb(struct proc_filter *pf, void *priv);