]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
parse.y: Fix type declaration for group_name
authorNikola Forró <nforro@redhat.com>
Mon, 6 Jan 2020 16:09:30 +0000 (09:09 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 8 Jan 2020 15:01:28 +0000 (08:01 -0700)
The group_name grammar rule was incorrectly defined as
returning a type<val> which is an int.  It actually returns
a type<name> which is a char *.

Having group_name declared as val (int) and assigning a char * value
to it can lead to crashes on platforms where pointer size exceeds
size of int.

On newer versions of Bison, this bug led to the following
warnings during compilation:

parse.y: In function ‘yyparse’:
parse.y:106:56: warning: passing argument 1 of
    ‘cgroup_config_insert_cgroup’ makes pointer from integer
    without a cast [-Wint-conversion]
    106 |    $$ = cgroup_config_insert_cgroup($2);
        |                                                        ^
        |                                                        |
        |                                                        int

In file included from parse.y:21:
./libcgroup-internal.h:231:39: note: expected ‘char *’ but argument is
    of type ‘int’
    231 | int cgroup_config_insert_cgroup(char *cg_name);
        |                                 ~~~~~~^~~~~~~

parse.y:125:15: warning: assignment to ‘int’ from ‘char *’ makes integer
    from pointer without a cast [-Wint-conversion]
    125 |   $$ = $1;
        |               ^

parse.y:129:15: warning: assignment to ‘int’ from ‘char *’ makes integer
    from pointer without a cast [-Wint-conversion]
    129 |   $$ = $1;
        |               ^

parse.y: In function ‘yyparse’:
parse.y:106:56: warning: passing argument 1 of
    ‘cgroup_config_insert_cgroup’ makes pointer from integer without a cast
    [-Wint-conversion]
    106 |    $$ = cgroup_config_insert_cgroup($2);
        |                                                        ^
        |                                                        |
        |                                                        int

In file included from parse.y:21:
./libcgroup-internal.h:231:39: note: expected ‘char *’ but argument is
    of type ‘int’
    231 | int cgroup_config_insert_cgroup(char *cg_name);
        |                                 ~~~~~~^~~~~~~
parse.y:125:15: warning: assignment to ‘int’ from ‘char *’ makes integer
    from pointer without a cast [-Wint-conversion]
    125 |   $$ = $1;
        |               ^

parse.y:129:15: warning: assignment to ‘int’ from ‘char *’ makes integer
    from pointer without a cast [-Wint-conversion]
    129 |   $$ = $1;
        |               ^

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Signed-off-by: Nikola Forró <nforro@redhat.com>
Acked-by: Michal Koutný <mkoutny@suse.com>
src/parse.y

index 98f7699d2c00e7e19aa07f961223cbbc2fb6a684..e67ad54e6f349f808e8669e40e4c00c4078c7638 100644 (file)
@@ -45,9 +45,9 @@ int yywrap(void)
        int val;
        struct cgroup_dictionary *values;
 }
-%type <name> ID DEFAULT
+%type <name> ID DEFAULT group_name
 %type <val> mountvalue_conf mount task_namevalue_conf admin_namevalue_conf
-%type <val> admin_conf task_conf task_or_admin group_conf group start group_name
+%type <val> admin_conf task_conf task_or_admin group_conf group start
 %type <val> namespace namespace_conf default default_conf
 %type <values> namevalue_conf
 %type <val> template template_conf