]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
src: Buffer is null terminated.
authorVarsha Rao <rvarsha016@gmail.com>
Wed, 20 Sep 2017 16:23:09 +0000 (21:53 +0530)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 27 Sep 2017 12:04:00 +0000 (14:04 +0200)
In _snprintf() functions definition the buffer is null terminated.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
44 files changed:
src/chain.c
src/common.c
src/expr.c
src/expr/bitwise.c
src/expr/byteorder.c
src/expr/cmp.c
src/expr/counter.c
src/expr/ct.c
src/expr/data_reg.c
src/expr/dup.c
src/expr/dynset.c
src/expr/exthdr.c
src/expr/fib.c
src/expr/fwd.c
src/expr/hash.c
src/expr/immediate.c
src/expr/limit.c
src/expr/log.c
src/expr/lookup.c
src/expr/masq.c
src/expr/match.c
src/expr/meta.c
src/expr/nat.c
src/expr/numgen.c
src/expr/objref.c
src/expr/payload.c
src/expr/queue.c
src/expr/quota.c
src/expr/range.c
src/expr/redir.c
src/expr/reject.c
src/expr/rt.c
src/expr/target.c
src/gen.c
src/obj/counter.c
src/obj/ct_helper.c
src/obj/limit.c
src/obj/quota.c
src/object.c
src/rule.c
src/ruleset.c
src/set.c
src/set_elem.c
src/table.c

index d2fafd5b78c05ee00090e558564d7e34fbc0b039..6df871df4131d5c5ecaea8bdb764025bd3fff3c9 100644 (file)
@@ -827,6 +827,9 @@ static int nftnl_chain_cmd_snprintf(char *buf, size_t size,
 {
        int ret, remain = size, offset = 0;
 
+       if (size)
+               buf[0] = '\0';
+
        ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
@@ -853,14 +856,20 @@ static int nftnl_chain_cmd_snprintf(char *buf, size_t size,
 int nftnl_chain_snprintf(char *buf, size_t size, const struct nftnl_chain *c,
                         uint32_t type, uint32_t flags)
 {
-       return nftnl_chain_cmd_snprintf(buf, size, c, nftnl_flag2cmd(flags), type,
-                                     flags);
+       if (size)
+               buf[0] = '\0';
+
+       return nftnl_chain_cmd_snprintf(buf, size, c, nftnl_flag2cmd(flags),
+                                       type, flags);
 }
 EXPORT_SYMBOL(nftnl_chain_snprintf);
 
 static int nftnl_chain_do_snprintf(char *buf, size_t size, const void *c,
                                   uint32_t cmd, uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_chain_snprintf(buf, size, c, type, flags);
 }
 
index a95883c19080843333a6c0a4d129d672bc662d97..ba5a49fc84700166384a8256c376d62ed1342667 100644 (file)
@@ -94,6 +94,9 @@ EXPORT_SYMBOL(nftnl_parse_perror);
 int nftnl_cmd_header_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type,
                            uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        NFTNL_BUF_INIT(b, buf, size);
 
        if (cmd == NFTNL_CMD_UNSPEC)
@@ -135,6 +138,9 @@ int nftnl_cmd_header_fprintf(FILE *fp, uint32_t cmd, uint32_t type,
 int nftnl_cmd_footer_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type,
                            uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        NFTNL_BUF_INIT(b, buf, size);
 
        if (cmd == NFTNL_CMD_UNSPEC)
index a077cce07dbe1abbcb00e921eae6848422e780fe..c5fcf06492ae2bf8c3c189078ee516380ea0628a 100644 (file)
@@ -281,6 +281,9 @@ int nftnl_expr_snprintf(char *buf, size_t size, const struct nftnl_expr *expr,
        int ret;
        unsigned int offset = 0, remain = size;
 
+       if (size)
+               buf[0] = '\0';
+
        if (!expr->ops->snprintf)
                return 0;
 
index a89734b5f2d4e9f3eeef5a8b0c420a1fa06cfd2b..ff9ade4d86d001d205eeefa32a056aa7ef161922 100644 (file)
@@ -257,6 +257,9 @@ static int
 nftnl_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type,
                            uint32_t flags, const struct nftnl_expr *e)
 {
+       if (size)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_bitwise_snprintf_default(buf, size, e);
index 47c04cfea69fb9341631c5cd2deb36155ad54ed1..4bb95b497701ead4c424478aff0e2686db78d468 100644 (file)
@@ -272,6 +272,9 @@ static int
 nftnl_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type,
                              uint32_t flags, const struct nftnl_expr *e)
 {
+       if (size)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_byteorder_snprintf_default(buf, size, e);
index b26d0eb08bb20f6274c0b7da9e31a8057da70522..7bafaec573e771585893fc7e590e72a9c2274351 100644 (file)
@@ -246,6 +246,9 @@ static int
 nftnl_expr_cmp_snprintf(char *buf, size_t size, uint32_t type,
                        uint32_t flags, const struct nftnl_expr *e)
 {
+       if (size)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_cmp_snprintf_default(buf, size, e);
index 21901e892471ee808e15a2a82f38334666d06c42..5c196d451843195230297a41f537ea35e15b9a57 100644 (file)
@@ -164,6 +164,9 @@ static int nftnl_expr_counter_snprintf(char *buf, size_t len, uint32_t type,
                                       uint32_t flags,
                                       const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_counter_snprintf_default(buf, len, e);
index 6f87a72487ae742e30f5d6805958771ef2f9edcb..021a27795a690e39a03c58741f503f9283afbd99 100644 (file)
@@ -317,6 +317,9 @@ static int
 nftnl_expr_ct_snprintf(char *buf, size_t len, uint32_t type,
                       uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_ct_snprintf_default(buf, len, e);
index a246952f7f01be4147582c273ca4aa2ca6eb0b95..c925e2013c2fda7371386c37d0912643a435e278 100644 (file)
@@ -194,6 +194,9 @@ int nftnl_data_reg_snprintf(char *buf, size_t size,
                            uint32_t output_format, uint32_t flags,
                            int reg_type)
 {
+       if (size)
+               buf[0] = '\0';
+
        switch(reg_type) {
        case DATA_VALUE:
                switch(output_format) {
index ed8e6208cfabaf0b82ae4c401b415cf1fffe763c..e2171f4ef1fb762e591b85eb97a62040dd22371e 100644 (file)
@@ -170,6 +170,9 @@ static int nftnl_expr_dup_snprintf_default(char *buf, size_t len,
 static int nftnl_expr_dup_snprintf(char *buf, size_t len, uint32_t type,
                                   uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_dup_snprintf_default(buf, len, e, flags);
index 861879efd688ef3d74ce4446390636188ec83a49..2755d492e085cb7c0cbcc1d38465e875a29298d4 100644 (file)
@@ -314,6 +314,8 @@ static int
 nftnl_expr_dynset_snprintf(char *buf, size_t size, uint32_t type,
                           uint32_t flags, const struct nftnl_expr *e)
 {
+       if (size)
+               buf[0] = '\0';
 
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
index 75cafbc113f73f0523872162a41f107efd8de303..11766fafc0278f1c0637c0c4ac2fca2e3232ae24 100644 (file)
@@ -339,6 +339,9 @@ static int
 nftnl_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type,
                           uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_exthdr_snprintf_default(buf, len, e);
index b922b26681e799a7ac2986ccbac469eec6107ea2..cbadeef7ce4976c733c588530160ff58fb4d67ea 100644 (file)
@@ -236,6 +236,9 @@ static int
 nftnl_expr_fib_snprintf(char *buf, size_t len, uint32_t type,
                         uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_fib_snprintf_default(buf, len, e);
index 1312ea10b07c465ca1806cc4b441f8883f4f8b66..38923df647603da7060a84050fc27f554b8e9afa 100644 (file)
@@ -147,6 +147,9 @@ static int nftnl_expr_fwd_snprintf_default(char *buf, size_t len,
 static int nftnl_expr_fwd_snprintf(char *buf, size_t len, uint32_t type,
                                   uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_fwd_snprintf_default(buf, len, e, flags);
index fcc4fa5c051611306a95e078f6f72e997a73037e..066c790d5b5085fc487115587e64f169f20fc73c 100644 (file)
@@ -288,6 +288,9 @@ static int
 nftnl_expr_hash_snprintf(char *buf, size_t len, uint32_t type,
                         uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_hash_snprintf_default(buf, len, e);
index b0570bd539a4e409f9021f53981a8924e804e206..aba84ea0823e352fd18c3f6fc8b8108e7f93c2c3 100644 (file)
@@ -262,6 +262,9 @@ static int
 nftnl_expr_immediate_snprintf(char *buf, size_t len, uint32_t type,
                              uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch(type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_immediate_snprintf_default(buf, len, e, flags);
index 856ab1839b0a6fbf88af47a92730516202c9d56e..8e1f02abb617c5a1f38623b34c76352aef5a4d49 100644 (file)
@@ -243,6 +243,9 @@ static int
 nftnl_expr_limit_snprintf(char *buf, size_t len, uint32_t type,
                          uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch(type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_limit_snprintf_default(buf, len, e);
index 86d965136cd4c6c574f9987c70783f5aa47d6348..161327b4b5f236f9e6e074e367fd04a16a49f664 100644 (file)
@@ -301,6 +301,9 @@ static int
 nftnl_expr_log_snprintf(char *buf, size_t len, uint32_t type,
                        uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch(type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_log_snprintf_default(buf, len, e);
index e4c05ec1763bf9b772cfcce30206d4de306a7e90..32220a30dbce10958b41e5944f619e5cf35c1d40 100644 (file)
@@ -242,6 +242,8 @@ static int
 nftnl_expr_lookup_snprintf(char *buf, size_t size, uint32_t type,
                           uint32_t flags, const struct nftnl_expr *e)
 {
+       if (size)
+               buf[0] = '\0';
 
        switch(type) {
        case NFTNL_OUTPUT_DEFAULT:
index 7c235d3b0bdc75dbc508ed369c2d9f9728fcc75d..1c75ee9cdd53b1ad28fa03f80b032d401b2635dc 100644 (file)
@@ -190,6 +190,9 @@ static int nftnl_expr_masq_snprintf_default(char *buf, size_t len,
 static int nftnl_expr_masq_snprintf(char *buf, size_t len, uint32_t type,
                                    uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_masq_snprintf_default(buf, len, e);
index dd09e1e851925579b393ffae1558a9d7e14d74a3..af659b3821c8f38765b5d7858fce15d411dac6d3 100644 (file)
@@ -200,6 +200,9 @@ nftnl_expr_match_snprintf(char *buf, size_t len, uint32_t type,
 {
        struct nftnl_expr_match *match = nftnl_expr_data(e);
 
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return snprintf(buf, len, "name %s rev %u ",
index 2c758412bf2e3f1791636628a7c9f1693eed7cad..b5c27e66dc51361d214c7ed9130b0166b1793c2f 100644 (file)
@@ -252,6 +252,9 @@ static int
 nftnl_expr_meta_snprintf(char *buf, size_t len, uint32_t type,
                         uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_meta_snprintf_default(buf, len, e);
index 92713033a6e766b81137a207a5eb48cebfe6eabf..350633fd5e0a0db9eadc089f87942e3a6719f66a 100644 (file)
@@ -339,6 +339,9 @@ static int
 nftnl_expr_nat_snprintf(char *buf, size_t size, uint32_t type,
                        uint32_t flags, const struct nftnl_expr *e)
 {
+       if (size)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_nat_snprintf_default(buf, size, e);
index 1369b01d9401d825b69662c1d7e04360fb8d8f14..9b5b1b7892069b68f930d696b8a2e9bf18531dbe 100644 (file)
@@ -224,6 +224,9 @@ static int
 nftnl_expr_ng_snprintf(char *buf, size_t len, uint32_t type,
                       uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_ng_snprintf_default(buf, len, e);
index 4cfa3cbfbd2b570cb02030b2a6350adeebc40a5a..b4b3383e8a7ca49b37ab433e123c0876e8e1b5be 100644 (file)
@@ -236,6 +236,9 @@ static int nftnl_expr_objref_snprintf(char *buf, size_t len, uint32_t type,
                                      uint32_t flags,
                                      const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_objref_snprintf_default(buf, len, e);
index 91e1587ff239b3236705e9125e6588f4c4a359f9..897fc7746166e62a337ff60209ff796c05177d06 100644 (file)
@@ -290,6 +290,9 @@ nftnl_expr_payload_snprintf(char *buf, size_t len, uint32_t type,
 {
        struct nftnl_expr_payload *payload = nftnl_expr_data(e);
 
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                if (payload->sreg)
index f62db9fd5d46a92c894de11cba32ab646eab3c2e..e0fb785a490bb7740637d5b48b3ce2d60a255cb4 100644 (file)
@@ -235,6 +235,8 @@ static int
 nftnl_expr_queue_snprintf(char *buf, size_t len, uint32_t type,
                          uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
 
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
index 667e6e17c28ce159182408930fec84c9bf959da1..c247b0a03341565b369c80078325e9e185f6e8cd 100644 (file)
@@ -183,6 +183,9 @@ static int nftnl_expr_quota_snprintf(char *buf, size_t len, uint32_t type,
                                       uint32_t flags,
                                       const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_quota_snprintf_default(buf, len, e);
index b2789ffaada340b425bb7b07ac3b8804c5c52fda..c7bb7c7f3d7ada1030d10451cf4525a67e11b01a 100644 (file)
@@ -263,6 +263,9 @@ static int nftnl_expr_range_snprintf_default(char *buf, size_t size,
 static int nftnl_expr_range_snprintf(char *buf, size_t size, uint32_t type,
                                     uint32_t flags, const struct nftnl_expr *e)
 {
+       if (size)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_range_snprintf_default(buf, size, e);
index b2aa3453870a90a3cd88622d3ac8a6e25095b3cb..9fb634afaa193ee64183c5329aff3a9da967ec5b 100644 (file)
@@ -204,6 +204,9 @@ static int
 nftnl_expr_redir_snprintf(char *buf, size_t len, uint32_t type,
                          uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_redir_snprintf_default(buf, len, e);
index 11d8b20096aec74bf5779be275c673cb1bac8160..1e6fdf5c5ba035d8c6b50738b76d1ae900958678 100644 (file)
@@ -164,6 +164,9 @@ static int
 nftnl_expr_reject_snprintf(char *buf, size_t len, uint32_t type,
                           uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_reject_snprintf_default(buf, len, e);
index 62c01a0be0f523edf2802d9281b88b67b6640128..10cb1e27ce682a8ba99f32997b3d1b94ead6c97c 100644 (file)
@@ -203,6 +203,9 @@ static int
 nftnl_expr_rt_snprintf(char *buf, size_t len, uint32_t type,
                       uint32_t flags, const struct nftnl_expr *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_rt_snprintf_default(buf, len, e);
index ed4bf7df632879749a53cbe140862e318b58fabe..3c58b03d20dd0f0520a0ef63f1fc3f15d765d3d5 100644 (file)
@@ -200,6 +200,9 @@ nftnl_expr_target_snprintf(char *buf, size_t len, uint32_t type,
 {
        struct nftnl_expr_target *target = nftnl_expr_data(e);
 
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return snprintf(buf, len, "name %s rev %u ",
index e1d528022ba1b0f325904aa818a39301bf24f38a..a03648bba1c2e0ec704556b3a6f74e08edb0aaa6 100644 (file)
--- a/src/gen.c
+++ b/src/gen.c
@@ -168,6 +168,9 @@ static int nftnl_gen_cmd_snprintf(char *buf, size_t size,
 {
        int ret, remain = size, offset = 0;
 
+       if (size)
+               buf[0] = '\0';
+
        ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
@@ -188,7 +191,10 @@ static int nftnl_gen_cmd_snprintf(char *buf, size_t size,
 
 int nftnl_gen_snprintf(char *buf, size_t size, const struct nftnl_gen *gen,
                       uint32_t type, uint32_t flags)
-{;
+{
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_gen_cmd_snprintf(buf, size, gen, nftnl_flag2cmd(flags), type,
                                    flags);
 }
@@ -197,6 +203,9 @@ EXPORT_SYMBOL(nftnl_gen_snprintf);
 static int nftnl_gen_do_snprintf(char *buf, size_t size, const void *gen,
                                 uint32_t cmd, uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf = '\0';
+
        return nftnl_gen_snprintf(buf, size, gen, type, flags);
 }
 
index beadc93a8c35267a345229369d8aa8c8082bac6e..332bb2b35fa2208043ea3d74a4dd0c28364ded61 100644 (file)
@@ -158,6 +158,9 @@ static int nftnl_obj_counter_snprintf(char *buf, size_t len, uint32_t type,
                                       uint32_t flags,
                                       const struct nftnl_obj *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_obj_counter_snprintf_default(buf, len, e);
index d6d3111ecce895902a0c23b6221d572962493055..62569fefe26f1e959abb510d8531f423ac23e73e 100644 (file)
@@ -185,6 +185,9 @@ static int nftnl_obj_ct_helper_snprintf(char *buf, size_t len, uint32_t type,
                                       uint32_t flags,
                                       const struct nftnl_obj *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_obj_ct_helper_snprintf_default(buf, len, e);
index 8cf0faa7933ff33d13fbdff56d24f14cdefe02fc..7f8bcf732b1827a2ca7e01611c3ee8adbcb6434c 100644 (file)
@@ -212,6 +212,9 @@ static int nftnl_obj_limit_snprintf(char *buf, size_t len, uint32_t type,
                                    uint32_t flags,
                                    const struct nftnl_obj *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_obj_limit_snprintf_default(buf, len, e);
index d5757b29d40de7ba0cc49d2ebf0beb1a225aa38f..6d3678465d40bfe4ae044a12a7c95e6c84a489ff 100644 (file)
@@ -179,6 +179,9 @@ static int nftnl_obj_quota_snprintf(char *buf, size_t len, uint32_t type,
                                       uint32_t flags,
                                       const struct nftnl_obj *e)
 {
+       if (len)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_obj_quota_snprintf_default(buf, len, e);
index d15ec10794ea03db833c8651406a40f169252bd4..8dc83b36c32eaf296bf9f9871fc8350e675ad2ac 100644 (file)
@@ -448,6 +448,9 @@ static int nftnl_obj_cmd_snprintf(char *buf, size_t size,
 {
        int ret, remain = size, offset = 0;
 
+       if (size)
+               buf[0] = '\0';
+
        ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
@@ -474,6 +477,9 @@ static int nftnl_obj_cmd_snprintf(char *buf, size_t size,
 int nftnl_obj_snprintf(char *buf, size_t size, const struct nftnl_obj *obj,
                       uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_obj_cmd_snprintf(buf, size, obj, nftnl_flag2cmd(flags),
                                      type, flags);
 }
@@ -482,6 +488,9 @@ EXPORT_SYMBOL(nftnl_obj_snprintf);
 static int nftnl_obj_do_snprintf(char *buf, size_t size, const void *obj,
                                 uint32_t cmd, uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_obj_snprintf(buf, size, obj, type, flags);
 }
 
index 262d928ad2f06a3853b6c49e751556575e295143..f37806c0e07b9f679547de8e3172e5395883598f 100644 (file)
@@ -792,6 +792,9 @@ static int nftnl_rule_cmd_snprintf(char *buf, size_t size,
        int ret, remain = size, offset = 0;
        uint32_t inner_flags = flags;
 
+       if (size)
+               buf[0] = '\0';
+
        inner_flags &= ~NFTNL_OF_EVENT_ANY;
 
        ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
@@ -822,6 +825,9 @@ static int nftnl_rule_cmd_snprintf(char *buf, size_t size,
 int nftnl_rule_snprintf(char *buf, size_t size, const struct nftnl_rule *r,
                        uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_rule_cmd_snprintf(buf, size, r, nftnl_flag2cmd(flags), type,
                                     flags);
 }
@@ -830,6 +836,9 @@ EXPORT_SYMBOL(nftnl_rule_snprintf);
 static int nftnl_rule_do_snprintf(char *buf, size_t size, const void *r,
                                  uint32_t cmd, uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_rule_snprintf(buf, size, r, type, flags);
 }
 
index 1f20cc56ec4af3fbdfdae38de9a6682f7fa2db72..cc43866c13bce825f0a02f096870c357abd107c5 100644 (file)
@@ -846,6 +846,9 @@ nftnl_ruleset_do_snprintf(char *buf, size_t size, const struct nftnl_ruleset *rs
        void *prev = NULL;
        uint32_t inner_flags = flags;
 
+       if (size)
+               buf[0] = '\0';
+
        /* dont pass events flags to child calls of _snprintf() */
        inner_flags &= ~NFTNL_OF_EVENT_ANY;
 
@@ -919,6 +922,9 @@ static int nftnl_ruleset_cmd_snprintf(char *buf, size_t size,
                                    const struct nftnl_ruleset *r, uint32_t cmd,
                                    uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
        case NFTNL_OUTPUT_JSON:
@@ -933,6 +939,9 @@ static int nftnl_ruleset_cmd_snprintf(char *buf, size_t size,
 int nftnl_ruleset_snprintf(char *buf, size_t size, const struct nftnl_ruleset *r,
                         uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
        case NFTNL_OUTPUT_JSON:
index 25a6fbfc063c4d348bc53b355ccc76247eb4d31c..a4e41d2a35475cf9e13bc2e0e4468ee8e79addbe 100644 (file)
--- a/src/set.c
+++ b/src/set.c
@@ -895,6 +895,9 @@ static int nftnl_set_cmd_snprintf(char *buf, size_t size,
        if (type == NFTNL_OUTPUT_XML)
                return 0;
 
+       if (size)
+               buf[0] = '\0';
+
        /* prevent set_elems to print as events */
        inner_flags &= ~NFTNL_OF_EVENT_ANY;
 
@@ -925,6 +928,9 @@ static int nftnl_set_cmd_snprintf(char *buf, size_t size,
 int nftnl_set_snprintf(char *buf, size_t size, const struct nftnl_set *s,
                       uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_set_cmd_snprintf(buf, size, s, nftnl_flag2cmd(flags), type,
                                    flags);
 }
@@ -933,6 +939,9 @@ EXPORT_SYMBOL(nftnl_set_snprintf);
 static int nftnl_set_do_snprintf(char *buf, size_t size, const void *s,
                                 uint32_t cmd, uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_set_snprintf(buf, size, s, type, flags);
 }
 
index 532b33f61d3d4d59434fec6a9b02b1afe1ece40d..a8f88a4f1813d7a3b5e6f514631f9e0416d34895 100644 (file)
@@ -696,6 +696,8 @@ static int nftnl_set_elem_cmd_snprintf(char *buf, size_t size,
 
        if (type == NFTNL_OUTPUT_XML)
                return 0;
+       if (size)
+               buf[0] = '\0';
 
        ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
@@ -724,6 +726,9 @@ int nftnl_set_elem_snprintf(char *buf, size_t size,
                            const struct nftnl_set_elem *e,
                            uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_set_elem_cmd_snprintf(buf, size, e, nftnl_flag2cmd(flags),
                                         type, flags);
 }
@@ -733,6 +738,9 @@ static int nftnl_set_elem_do_snprintf(char *buf, size_t size, const void *e,
                                      uint32_t cmd, uint32_t type,
                                      uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_set_elem_snprintf(buf, size, e, type, flags);
 }
 
index 80f85df003846cda964a4609add89810bb7606f8..4d8176c9be7802f7988c2e6d780bda1af15fec22 100644 (file)
@@ -378,6 +378,9 @@ static int nftnl_table_cmd_snprintf(char *buf, size_t size,
 {
        int ret, remain = size, offset = 0;
 
+       if (size)
+               buf[0] = '\0';
+
        ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
@@ -403,6 +406,9 @@ static int nftnl_table_cmd_snprintf(char *buf, size_t size,
 int nftnl_table_snprintf(char *buf, size_t size, const struct nftnl_table *t,
                         uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_table_cmd_snprintf(buf, size, t, nftnl_flag2cmd(flags), type,
                                      flags);
 }
@@ -411,6 +417,9 @@ EXPORT_SYMBOL(nftnl_table_snprintf);
 static int nftnl_table_do_snprintf(char *buf, size_t size, const void *t,
                                   uint32_t cmd, uint32_t type, uint32_t flags)
 {
+       if (size)
+               buf[0] = '\0';
+
        return nftnl_table_snprintf(buf, size, t, type, flags);
 }