[PATCH xtables] xtables: add 'printf' attribute to xlate_add

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This allows gcc to check format string vs. passed arguments.
Fix the fallout from this as well, typical warning produced is:

libebt_mark_m.c:112:28: warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'long unsigned int' [-Wformat=]
   xt_xlate_add(xl, "and 0x%x %s0 ", info->mask, ...
                           ~^        ~~~~~~~~~~

so add the required casts or fixup format strings as needed.
libxt_conntrack also passed an unneeded argument (port), so remove that.

Signed-off-by: Florian Westphal <fw@xxxxxxxxx>
---
 extensions/libebt_mark_m.c   | 8 ++++----
 extensions/libxt_MARK.c      | 6 +++---
 extensions/libxt_conntrack.c | 6 +++---
 extensions/libxt_hashlimit.c | 6 +++---
 include/xtables.h            | 2 +-
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/extensions/libebt_mark_m.c b/extensions/libebt_mark_m.c
index 7bde77d95ffa..64ad926f1995 100644
--- a/extensions/libebt_mark_m.c
+++ b/extensions/libebt_mark_m.c
@@ -109,14 +109,14 @@ static int brmark_m_xlate(struct xt_xlate *xl,
 	xt_xlate_add(xl, "meta mark ");
 
 	if (info->bitmask == EBT_MARK_OR) {
-		xt_xlate_add(xl, "and 0x%x %s0 ", info->mask,
+		xt_xlate_add(xl, "and 0x%x %s0 ", (uint32_t)info->mask,
 			     info->invert ? "" : "!= ");
 	} else if (info->mask != 0xffffffffU) {
-		xt_xlate_add(xl, "and 0x%x %s0x%x ", info->mask,
-			   op == XT_OP_EQ ? "" : "!= ", info->mark);
+		xt_xlate_add(xl, "and 0x%x %s0x%x ", (uint32_t)info->mask,
+			   op == XT_OP_EQ ? "" : "!= ", (uint32_t)info->mark);
 	} else {
 		xt_xlate_add(xl, "%s0x%x ",
-			   op == XT_OP_EQ ? "" : "!= ", info->mark);
+			   op == XT_OP_EQ ? "" : "!= ", (uint32_t)info->mark);
 	}
 
 	return 1;
diff --git a/extensions/libxt_MARK.c b/extensions/libxt_MARK.c
index 5c6186fe0340..43aa977924b1 100644
--- a/extensions/libxt_MARK.c
+++ b/extensions/libxt_MARK.c
@@ -277,13 +277,13 @@ static int MARK_xlate(struct xt_xlate *xl,
 
 	switch(markinfo->mode) {
 	case XT_MARK_SET:
-		xt_xlate_add(xl, "0x%x ", markinfo->mark);
+		xt_xlate_add(xl, "0x%x ", (uint32_t)markinfo->mark);
 		break;
 	case XT_MARK_AND:
-		xt_xlate_add(xl, "mark and 0x%x ", markinfo->mark);
+		xt_xlate_add(xl, "mark and 0x%x ", (uint32_t)markinfo->mark);
 		break;
 	case XT_MARK_OR:
-		xt_xlate_add(xl, "mark or 0x%x ", markinfo->mark);
+		xt_xlate_add(xl, "mark or 0x%x ", (uint32_t)markinfo->mark);
 		break;
 	}
 
diff --git a/extensions/libxt_conntrack.c b/extensions/libxt_conntrack.c
index daa8c15a5fab..1817d335cb19 100644
--- a/extensions/libxt_conntrack.c
+++ b/extensions/libxt_conntrack.c
@@ -1271,9 +1271,9 @@ static int _conntrack3_mt_xlate(struct xt_xlate *xl,
 			     sinfo->invert_flags & XT_CONNTRACK_EXPIRES ?
 			     "!= " : "");
 		if (sinfo->expires_max == sinfo->expires_min)
-			xt_xlate_add(xl, "%lu", sinfo->expires_min);
+			xt_xlate_add(xl, "%u", sinfo->expires_min);
 		else
-			xt_xlate_add(xl, "%lu-%lu", sinfo->expires_min,
+			xt_xlate_add(xl, "%u-%u", sinfo->expires_min,
 				     sinfo->expires_max);
 		space = " ";
 	}
@@ -1365,7 +1365,7 @@ static int _conntrack3_mt_xlate(struct xt_xlate *xl,
 	if (sinfo->match_flags & XT_CONNTRACK_REPLDST_PORT) {
 		xt_xlate_add(xl, "%sct reply proto-dst %s", space,
 			     sinfo->invert_flags & XT_CONNTRACK_REPLDST_PORT ?
-			     "!= " : "", sinfo->repldst_port);
+			     "!= " : "");
 		if (sinfo->repldst_port == sinfo->repldst_port_high)
 			xt_xlate_add(xl, "%u", sinfo->repldst_port);
 		else
diff --git a/extensions/libxt_hashlimit.c b/extensions/libxt_hashlimit.c
index 7d78d852db1f..f3b6e04309bd 100644
--- a/extensions/libxt_hashlimit.c
+++ b/extensions/libxt_hashlimit.c
@@ -1221,7 +1221,7 @@ static void print_packets_rate_xlate(struct xt_xlate *xl, uint64_t avg,
 		    _rates[i].mult / avg < _rates[i].mult % avg)
 			break;
 
-	xt_xlate_add(xl, " %llu/%s ",
+	xt_xlate_add(xl, " %" PRIu64 "/%s ",
 		     _rates[i-1].mult / avg, _rates[i-1].name);
 }
 
@@ -1354,7 +1354,7 @@ static int hashlimit_mt_xlate(struct xt_xlate *xl, const char *name,
 	else {
 		print_packets_rate_xlate(xl, cfg->avg, revision);
 		if (cfg->burst != XT_HASHLIMIT_BURST)
-			xt_xlate_add(xl, "burst %lu packets", cfg->burst);
+			xt_xlate_add(xl, "burst %" PRIu64 " packets", (uint64_t)cfg->burst);
 
 	}
 	xt_xlate_add(xl, "}");
@@ -1372,7 +1372,7 @@ static int hashlimit_xlate(struct xt_xlate *xl,
 	ret = hashlimit_mode_xlate(xl, info->cfg.mode, NFPROTO_IPV4, 32, 32);
 	xt_xlate_add(xl, " timeout %us limit rate", info->cfg.expire / 1000);
 	print_packets_rate_xlate(xl, info->cfg.avg, 1);
-	xt_xlate_add(xl, " burst %lu packets", info->cfg.burst);
+	xt_xlate_add(xl, " burst %u packets", info->cfg.burst);
 	xt_xlate_add(xl, "}");
 
 	return ret;
diff --git a/include/xtables.h b/include/xtables.h
index 2bc190cd5d40..4aa084a1a2a3 100644
--- a/include/xtables.h
+++ b/include/xtables.h
@@ -627,7 +627,7 @@ extern const char *xtables_lmap_id2name(const struct xtables_lmap *, int);
 /* xlate infrastructure */
 struct xt_xlate *xt_xlate_alloc(int size);
 void xt_xlate_free(struct xt_xlate *xl);
-void xt_xlate_add(struct xt_xlate *xl, const char *fmt, ...);
+void xt_xlate_add(struct xt_xlate *xl, const char *fmt, ...) __attribute__((format(printf,2,3)));
 void xt_xlate_add_comment(struct xt_xlate *xl, const char *comment);
 const char *xt_xlate_get_comment(struct xt_xlate *xl);
 const char *xt_xlate_get(struct xt_xlate *xl);
-- 
2.18.1




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux