summaryrefslogtreecommitdiffstats
path: root/src/rule.c
diff options
context:
space:
mode:
authorArturo Borrero <arturo.borrero.glez@gmail.com>2013-09-26 00:13:08 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-09-27 16:02:08 +0200
commita54e60a541f009639d596e1fecaeeab67683d258 (patch)
tree213abd63d64d7e39e5e0d3e0f1f3cca3e8bc1a58 /src/rule.c
parent3e40a89d43db8cf6c5947baa7221e57e2b9cf351 (diff)
src: snprintf: fix buffer lengths
Use 'len' instead of 'size' since we need the remaining unused bytes in the buffer, not its total size. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/rule.c')
-rw-r--r--src/rule.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/rule.c b/src/rule.c
index 5fd8814..550b325 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -705,7 +705,7 @@ static int nft_rule_snprintf_json(char *buf, size_t size, struct nft_rule *r,
int ret, len = size, offset = 0;
struct nft_rule_expr *expr;
- ret = snprintf(buf, size,
+ ret = snprintf(buf, len,
"{ \"rule\": { \"family\" : \"%s\", \"table\" : \"%s\", "
"\"chain\" : \"%s\", \"handle\" : %llu,",
nft_family2str(r->family), r->table, r->chain,
@@ -759,7 +759,7 @@ static int nft_rule_snprintf_xml(char *buf, size_t size, struct nft_rule *r,
int ret, len = size, offset = 0;
struct nft_rule_expr *expr;
- ret = snprintf(buf, size, "<rule><family>%s</family>"
+ ret = snprintf(buf, len, "<rule><family>%s</family>"
"<table>%s</table><chain>%s</chain>"
"<handle>%llu</handle><flags>%u</flags>",
nft_family2str(r->family), r->table, r->chain,
@@ -786,7 +786,8 @@ static int nft_rule_snprintf_xml(char *buf, size_t size, struct nft_rule *r,
"<expr type=\"%s\">", expr->ops->name);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
- ret = nft_rule_expr_snprintf(buf+offset, size, expr, type, flags);
+ ret = nft_rule_expr_snprintf(buf+offset, len, expr,
+ type, flags);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
ret = snprintf(buf+offset, len, "</expr>");
@@ -805,7 +806,7 @@ static int nft_rule_snprintf_default(char *buf, size_t size, struct nft_rule *r,
struct nft_rule_expr *expr;
int ret, len = size, offset = 0;
- ret = snprintf(buf, size, "%s %s %s %"PRIu64" %"PRIu64"\n",
+ ret = snprintf(buf, len, "%s %s %s %"PRIu64" %"PRIu64"\n",
nft_family2str(r->family), r->table, r->chain,
r->handle, r->position);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
@@ -814,7 +815,8 @@ static int nft_rule_snprintf_default(char *buf, size_t size, struct nft_rule *r,
ret = snprintf(buf+offset, len, " [ %s ", expr->ops->name);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
- ret = nft_rule_expr_snprintf(buf+offset, size, expr, type, flags);
+ ret = nft_rule_expr_snprintf(buf+offset, len, expr,
+ type, flags);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
ret = snprintf(buf+offset, len, "]\n");