]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser: fix crash if we add a chain with an error chain type
authorLiping Zhang <liping.zhang@spreadtrum.com>
Sun, 29 May 2016 11:25:37 +0000 (19:25 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 30 May 2016 09:55:47 +0000 (11:55 +0200)
If we add a chain and specify the nonexistent chain type, chain_type_name_lookup
will return a NULL pointer, and meet the assert condition in xstrdup.
Fix crash like this:

  # nft add chain filter input {type none hook input priority 0\;}
  nft: utils.c:63: xstrdup: Assertion `s != ((void *)0)' failed.
  Aborted (core dumped)

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/parser_bison.y

index 0452b8f408c110eacbdb17ecac1869d938499ab5..ef10dee26e1d044dc26d797bb1753f611feca3d7 100644 (file)
@@ -1124,12 +1124,14 @@ type_identifier         :       STRING  { $$ = $1; }
 
 hook_spec              :       TYPE            STRING          HOOK            STRING          dev_spec        PRIORITY        prio_spec
                        {
-                               $<chain>0->type         = xstrdup(chain_type_name_lookup($2));
-                               if ($<chain>0->type == NULL) {
+                               const char *chain_type = chain_type_name_lookup($2);
+
+                               if (chain_type == NULL) {
                                        erec_queue(error(&@2, "unknown chain type %s", $2),
                                                   state->msgs);
                                        YYERROR;
                                }
+                               $<chain>0->type         = xstrdup(chain_type);
                                xfree($2);
 
                                $<chain>0->hookstr      = chain_hookname_lookup($4);