From: Tom Hromatka Date: Tue, 7 Jan 2020 19:31:45 +0000 (-0700) Subject: wrapper.c: Fix potentially unterminated strings X-Git-Tag: v0.42~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f75193b4b717fe94b22186091b038313691db5b8;p=thirdparty%2Flibcgroup.git wrapper.c: Fix potentially unterminated strings This commit fixes two adjacent strncpys that could result in unterminated strings: CID 1412144 (#2 of 2): Buffer not null terminated (BUFFER_SIZE_WARNING)13. buffer_size_warning: Calling strncpy with a maximum size argument of 100 bytes on destination array cntl_value->value of size 100 bytes might leave the destination string unterminated. Signed-off-by: Tom Hromatka --- diff --git a/src/wrapper.c b/src/wrapper.c index ee98ac5c..20ecc139 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -196,7 +196,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'; cntl_value->dirty = true; controller->values[controller->index] = cntl_value; controller->index++;