Author: kevans
Date: Mon Aug  5 00:08:25 2019
New Revision: 350576
URL: https://svnweb.freebsd.org/changeset/base/350576

Log:
  ipfw: fix jail option after r348215
  
  r348215 changed jail_getid(3) to validate passed-in jids as active jails
  (as the function is documented to return -1 if the jail does not exist).
  This broke the jail option (in some cases?) as the jail historically hasn't
  needed to exist at the time of rule parsing; jids will get stored and later
  applied.
  
  Fix this caller to attempt to parse *av as a number first and just use it
  as-is to match historical behavior. jail_getid(3) must still be used in
  order for name arguments to work, but it's strictly a fallback in case we
  weren't given a number.
  
  Reported and tested by:       Ari Suutari <ari stonepile fi>
  Reviewed by:  ae
  MFC after:    3 days
  Differential Revision:        https://reviews.freebsd.org/D21128

Modified:
  head/sbin/ipfw/ipfw2.c

Modified: head/sbin/ipfw/ipfw2.c
==============================================================================
--- head/sbin/ipfw/ipfw2.c      Sun Aug  4 21:43:34 2019        (r350575)
+++ head/sbin/ipfw/ipfw2.c      Mon Aug  5 00:08:25 2019        (r350576)
@@ -4674,12 +4674,27 @@ read_options:
                case TOK_JAIL:
                        NEED1("jail requires argument");
                    {
+                       char *end;
                        int jid;
 
                        cmd->opcode = O_JAIL;
-                       jid = jail_getid(*av);
-                       if (jid < 0)
-                               errx(EX_DATAERR, "%s", jail_errmsg);
+                       /*
+                        * If av is a number, then we'll just pass it as-is.  If
+                        * it's a name, try to resolve that to a jid.
+                        *
+                        * We save the jail_getid(3) call for a fallback because
+                        * it entails an unconditional trip to the kernel to
+                        * either validate a jid or resolve a name to a jid.
+                        * This specific token doesn't currently require a
+                        * jid to be an active jail, so we save a transition
+                        * by simply using a number that we're given.
+                        */
+                       jid = strtoul(*av, &end, 10);
+                       if (*end != '\0') {
+                               jid = jail_getid(*av);
+                               if (jid < 0)
+                                   errx(EX_DATAERR, "%s", jail_errmsg);
+                       }
                        cmd32->d[0] = (uint32_t)jid;
                        cmd->len |= F_INSN_SIZE(ipfw_insn_u32);
                        av++;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to