From: Kamalesh Babulal Date: Wed, 25 May 2022 13:40:10 +0000 (-0600) Subject: api.c: fix coverity out of bounds read warning X-Git-Tag: v3.0~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a5e918f08b73c5aa6c7ae2122ac9b066e51cead;p=thirdparty%2Flibcgroup.git api.c: fix coverity out of bounds read warning Fix out of bounds read, reported by Coverity tool: CID 1412156 (#1 of 1): Out-of-bounds read (OVERRUN). overrun-local: Overrunning array cgroup_strerror_codes of 30 8-byte elements at element index 49999 (byte offset 399999) using index code % ECGROUPNOTCOMPILED (which evaluates to 49999). Reproducer: ----------- $ cat cgrp-strerr.c int main(void) { int err = ECGNONEMPTY; fprintf(stderr, "%s\n", cgroup_strerror(err)); return 0; } without the patch: ----------------- $ ./cgrp-stderr (null) with the patch: --------------- $ ./cgrp-stderr Failed to remove a non-empty group Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index 198c793d..42d3beb5 100644 --- a/src/api.c +++ b/src/api.c @@ -119,6 +119,7 @@ const char * const cgroup_strerror_codes[] = { "Cgroup parsing failed", "Cgroup, rules file does not exist", "Cgroup mounting failed", + "", /* 50022 is reserved for future errors */ "End of File or iterator", "Failed to parse config file", "Have multiple paths for the same namespace",