]> granicus.if.org Git - ipset/commitdiff
Fix parsing service names for ports
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Tue, 10 Apr 2018 18:48:35 +0000 (20:48 +0200)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Tue, 10 Apr 2018 18:48:35 +0000 (20:48 +0200)
Parsing is attempted both for numbers and service names and
the temporary stored error message triggered to reset the state
parameters about the set. Reported by Yuri D'Elia.

Make_global.am
include/libipset/session.h
lib/libipset.map
lib/parse.c
lib/session.c
tests/hash:ip,port.t

index 4b0ac11f0398b530e9448ff0efba296abbde871e..10334cc26d68fc28bb51f704f7cdae5c642baea6 100644 (file)
@@ -69,7 +69,7 @@
 # interface. 
 
 #            curr:rev:age
-LIBVERSION = 11:0:0
+LIBVERSION = 11:1:1
 
 AM_CPPFLAGS = $(kinclude_CFLAGS) $(all_includes) -I$(top_srcdir)/include
 
index 833f763a3940f29c6d2e875095fa11ca96e8628f..bac4d19c8870aaf71bc3b4315fbb980a0fa4240f 100644 (file)
@@ -42,6 +42,7 @@ enum ipset_err_type {
 extern int ipset_session_report(struct ipset_session *session,
                                enum ipset_err_type type,
                                const char *fmt, ...);
+extern int ipset_session_warning_as_error(struct ipset_session *session);
 
 #define ipset_err(session, fmt, args...) \
        ipset_session_report(session, IPSET_ERROR, fmt , ## args)
index a2e9bd356113705dbb6fdb04a4080f30243b03b8..475fae517fbdaf2dd73f50437019246d91de4fe8 100644 (file)
@@ -168,3 +168,8 @@ LIBIPSET_4.6 {
 global:
   ipset_keyword;
 } LIBIPSET_4.5;
+
+LIBIPSET_4.7 {
+global:
+  ipset_session_warning_as_error;
+} LIBIPSET_4.6;
index bc8e7773f05d623afd4ce819a2bf8f78003bba95..7cd643632be84d3d5aa4a53974232768871b8efc 100644 (file)
@@ -292,7 +292,8 @@ parse_portname(struct ipset_session *session, const char *str,
 
 error:
        free(saved);
-       return syntax_err("cannot parse '%s' as a %s port", str, proto);
+       return ipset_warn(session, "cannot parse '%s' as a %s port",
+                         str, proto);
 }
 
 /**
@@ -313,21 +314,22 @@ ipset_parse_port(struct ipset_session *session,
                 const char *proto)
 {
        uint16_t port;
-       int err;
 
        assert(session);
        assert(opt == IPSET_OPT_PORT || opt == IPSET_OPT_PORT_TO);
        assert(str);
 
-       if ((err = string_to_u16(session, str, &port)) == 0 ||
-           (err = parse_portname(session, str, &port, proto)) == 0)
-               err = ipset_session_data_set(session, opt, &port);
-
-       if (!err)
-               /* No error, so reset false error messages! */
+       if (parse_portname(session, str, &port, proto) == 0) {
+               return ipset_session_data_set(session, opt, &port);
+       }
+       /* Error is stored as warning in session report */
+       if (string_to_u16(session, str, &port) == 0) {
+               /* No error, so reset false error messages */
                ipset_session_report_reset(session);
-
-       return err;
+               return ipset_session_data_set(session, opt, &port);
+       }
+       /* Restore warning as error */
+       return ipset_session_warning_as_error(session);
 }
 
 /**
index b1c5f5ebdce5c75155b603b27c1c15d8b7548668..ca96aaa57ea6277e407018c493ecfb89eae4a478 100644 (file)
@@ -239,6 +239,21 @@ ipset_session_report(struct ipset_session *session,
        return -1;
 }
 
+/**
+ * ipset_session_warning_as_error - set warning as error
+ * @session: session structrure
+ *
+ * Returns -1.
+ */
+int
+ipset_session_warning_as_error(struct ipset_session *session)
+{
+       session->errmsg = session->report;
+       session->warnmsg = NULL;
+       ipset_data_reset(ipset_session_data(session));
+       return -1;
+}
+
 /**
  * ipset_session_reset - reset the report buffer
  * @session: session structure
index be323e05b52094ca08a02d5879a7c2776f40518d..aba8fdcfa33b0711a07372ddf6c0cf4e1949932e 100644 (file)
 0 ipset add test 2.0.0.0,5
 # Try to add value after second random value
 0 ipset add test 2.1.0.1,128
+# Add port by name
+0 ipset add test 2.1.0.3,smtp
+# Delete port by number
+0 ipset del test 2.1.0.3,25
 # List set
 0 ipset list test | grep -v Revision: | sed 's/timeout ./timeout x/' > .foo0 && ./sort.sh .foo0
 # Check listing