summaryrefslogtreecommitdiffstats
path: root/src/chain.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/chain.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/chain.c')
-rw-r--r--src/chain.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/chain.c b/src/chain.c
index 8c0d804..874116a 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -753,7 +753,7 @@ static int nft_chain_snprintf_json(char *buf, size_t size, struct nft_chain *c)
{
int ret, len = size, offset = 0;
- ret = snprintf(buf, size,
+ ret = snprintf(buf, len,
"{ \"chain\": {"
"\"name\": \"%s\","
"\"handle\": %"PRIu64","
@@ -768,7 +768,7 @@ static int nft_chain_snprintf_json(char *buf, size_t size, struct nft_chain *c)
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
if (c->flags & (1 << NFT_CHAIN_ATTR_HOOKNUM)) {
- ret = snprintf(buf+offset, size,
+ ret = snprintf(buf+offset, len,
",\"type\": \"%s\","
"\"hooknum\": \"%s\","
"\"prio\": %d,"
@@ -778,9 +778,7 @@ static int nft_chain_snprintf_json(char *buf, size_t size, struct nft_chain *c)
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}
- ret = snprintf(buf+offset, size,
- "}"
- "}");
+ ret = snprintf(buf+offset, len, "}}");
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
return offset;
@@ -790,14 +788,14 @@ static int nft_chain_snprintf_xml(char *buf, size_t size, struct nft_chain *c)
{
int ret, len = size, offset = 0;
- ret = snprintf(buf, size, "<chain><name>%s</name>"
+ ret = snprintf(buf, len, "<chain><name>%s</name>"
"<handle>%"PRIu64"</handle><bytes>%"PRIu64"</bytes>"
"<packets>%"PRIu64"</packets><table>%s</table>",
c->name, c->handle, c->bytes, c->packets, c->table);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
if (c->flags & (1 << NFT_CHAIN_ATTR_HOOKNUM)) {
- ret = snprintf(buf+offset, size,
+ ret = snprintf(buf+offset, len,
"<type>%s</type>"
"<hooknum>%s</hooknum>"
"<prio>%d</prio>"
@@ -807,7 +805,7 @@ static int nft_chain_snprintf_xml(char *buf, size_t size, struct nft_chain *c)
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}
- ret = snprintf(buf+offset, size, "<family>%s</family></chain>",
+ ret = snprintf(buf+offset, len, "<family>%s</family></chain>",
nft_family2str(c->family));
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
@@ -819,12 +817,12 @@ static int nft_chain_snprintf_default(char *buf, size_t size,
{
int ret, len = size, offset = 0;
- ret = snprintf(buf, size, "%s %s %s",
- nft_family2str(c->family), c->table, c->name);
+ ret = snprintf(buf, len, "%s %s %s",
+ nft_family2str(c->family), c->table, c->name);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
if (c->flags & (1 << NFT_CHAIN_ATTR_HOOKNUM)) {
- ret = snprintf(buf+offset, size,
+ ret = snprintf(buf+offset, len,
" type %s hook %s prio %d policy %s use %d "
"packets %"PRIu64" bytes %"PRIu64"",
c->type, nft_hooknum2str(c->family, c->hooknum),