]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
wrapper.c: Fix potentially unterminated strings 2/head
authorTom Hromatka <tom.hromatka@oracle.com>
Tue, 7 Jan 2020 19:31:45 +0000 (12:31 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 8 Jan 2020 15:01:39 +0000 (08:01 -0700)
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 <tom.hromatka@oracle.com>
src/wrapper.c

index ee98ac5c70d998d5617883c4a095ca6d62e7f039..20ecc13932a70d241343b19c11aa8e1d31d69efe 100644 (file)
@@ -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++;