In some special situations in wrapper.c
the strncpy strings can be copy in such a way there will not be the termination 
sign in the given space thus the string will remain unterminated.
This patch adds the termination characters

Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com>
---

 src/wrapper.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/wrapper.c b/src/wrapper.c
index 90c8bc3..ec87584 100644
--- a/src/wrapper.c
+++ b/src/wrapper.c
@@ -44,6 +44,7 @@ struct cgroup *cgroup_new_cgroup(const char *name)
 
        init_cgroup(cgroup);
        strncpy(cgroup->name, name, sizeof(cgroup->name));
+       cgroup->name[sizeof(cgroup->name) - 1] = '\0';
 
        return cgroup;
 }
@@ -78,6 +79,7 @@ struct cgroup_controller *cgroup_add_controller(struct cgroup 
*cgroup,
                return NULL;
 
        strncpy(controller->name, name, sizeof(controller->name));
+       controller->name[sizeof(controller->name) - 1] = '\0';
        controller->index = 0;
 
        cgroup->controller[cgroup->index] = controller;
@@ -140,7 +142,9 @@ int cgroup_add_value_string(struct cgroup_controller 
*controller,
                return ECGCONTROLLERCREATEFAILED;
 
        strncpy(cntl_value->name, name, sizeof(cntl_value->name));
+       cntl_value->name[sizeof(cntl_value->name) - 1] = '\0';
        strncpy(cntl_value->value, value, sizeof(cntl_value->value));
+       cntl_value->value[sizeof(cntl_value->value) - 1] = '\0';
        controller->values[controller->index] = cntl_value;
        controller->index++;
 
@@ -172,6 +176,7 @@ int cgroup_add_value_int64(struct cgroup_controller 
*controller,
 
        strncpy(cntl_value->name, name,
                        sizeof(cntl_value->name));
+       cntl_value->name[sizeof(cntl_value->name) - 1] = '\0';
        ret = snprintf(cntl_value->value,
          sizeof(cntl_value->value), "%" PRId64, value);
 
@@ -211,6 +216,7 @@ int cgroup_add_value_uint64(struct cgroup_controller 
*controller,
                return ECGCONTROLLERCREATEFAILED;
 
        strncpy(cntl_value->name, name, sizeof(cntl_value->name));
+       cntl_value->name[sizeof(cntl_value->name) - 1] = '\0';
        ret = snprintf(cntl_value->value, sizeof(cntl_value->value),
                                                "%" PRIu64, value);
 
@@ -250,6 +256,7 @@ int cgroup_add_value_bool(struct cgroup_controller 
*controller,
                return ECGCONTROLLERCREATEFAILED;
 
        strncpy(cntl_value->name, name, sizeof(cntl_value->name));
+       cntl_value->name[sizeof(cntl_value->name) - 1] = '\0';
 
        if (value)
                ret = snprintf(cntl_value->value,
@@ -415,6 +422,7 @@ int cgroup_set_value_string(struct cgroup_controller 
*controller,
                struct control_value *val = controller->values[i];
                if (!strcmp(val->name, name)) {
                        strncpy(val->value, value, CG_VALUE_MAX);
+                       val->value[sizeof(val->value) - 1] = '\0';
                        return 0;
                }
        }
@@ -608,6 +616,7 @@ struct cgroup *create_cgroup_from_name_value_pairs(const 
char *name,
                }
 
                strncpy(con, name_value[i].name, FILENAME_MAX);
+               con[FILENAME_MAX - 1] = '\0';
                strtok(con, ".");
 
                /* add relevant controller */


------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to