]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgsnapshot: fix wrong array size in is_ctrl_on_list()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 14 Sep 2022 14:04:14 +0000 (08:04 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 14 Sep 2022 14:04:30 +0000 (08:04 -0600)
GCC throws -Wstringop-overflow warning:

  CC       cgsnapshot-cgsnapshot.o
cgsnapshot.c: In function 'parse_controllers':
cgsnapshot.c:540:53: warning: 'is_ctlr_on_list' accessing 16777216 bytes in a region of size 409600 [-Wstringop-overflow=]
  540 |                         if ((!(flags & FL_LIST) || (is_ctlr_on_list(controllers, cont_names))) &&
      |                                                    ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cgsnapshot.c:540:53: note: referencing argument 2 of type 'char(*)[4096]'
cgsnapshot.c:495:12: note: in a call to function 'is_ctlr_on_list'
  495 | static int is_ctlr_on_list(char controllers[CG_CONTROLLER_MAX][FILENAME_MAX],
      |            ^~~~~~~~~~~~~~~
cgsnapshot.c:560:37: warning: 'is_ctlr_on_list' accessing 16777216 bytes in a region of size 409600 [-Wstringop-overflow=]
  560 |         if ((!(flags & FL_LIST) || (is_ctlr_on_list(controllers, cont_names))) &&
      |                                    ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cgsnapshot.c:560:37: note: referencing argument 2 of type 'char(*)[4096]'
cgsnapshot.c:495:12: note: in a call to function 'is_ctlr_on_list'
  495 | static int is_ctlr_on_list(char controllers[CG_CONTROLLER_MAX][FILENAME_MAX],
      |            ^~~~~~~~~~~~~~~

the warning is seen due to the mismatch in the array size of the second
argument passed to is_ctlr_on_list() from parse_controllers().  Fix,
this long standing warning by chaging the size of the second function
argument in is_ctrl_on_list().

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 4362c8d32d5d8813a9a40bebe744aeaec5fbf953)

src/tools/cgsnapshot.c

index 0d20a20300a8bf11610f9b2eacff44c9180c7d75..553c9b6f5700897b0d26016654cc953d2ca11011 100644 (file)
@@ -516,7 +516,7 @@ err:
 }
 
 static int is_ctlr_on_list(char controllers[CG_CONTROLLER_MAX][FILENAME_MAX],
-                       cont_name_t wanted_conts[FILENAME_MAX])
+                       cont_name_t wanted_conts[CG_CONTROLLER_MAX])
 {
        int i = 0;
        int j = 0;