From: Arturo Borrero <arturo.borrero.glez@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: pablo@netfilter.org
Subject: [libnftables PATCH 1/5] data_reg: xml: fix bytes movements
Date: Mon, 03 Jun 2013 22:44:51 +0200 [thread overview]
Message-ID: <20130603204451.27713.51887.stgit@nfdev.cica.es> (raw)
There was bad bits movements and calcules when XML printing/parsing.
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
src/expr/data_reg.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c
index 74ebe76..7d26175 100644
--- a/src/expr/data_reg.c
+++ b/src/expr/data_reg.c
@@ -15,6 +15,7 @@
#include <limits.h>
#include <arpa/inet.h>
#include <errno.h>
+#include <netinet/in.h>
#include <libmnl/libmnl.h>
#include <linux/netfilter.h>
@@ -205,7 +206,7 @@ static int nft_data_reg_value_xml_parse(union nft_data_reg *reg, char *xml)
reg->val[i] = utmp;
}
- reg->len = sizeof(reg->val);
+ reg->len = len*sizeof(reg->val[0]);
mxmlDelete(tree);
return 0;
@@ -259,8 +260,9 @@ int nft_data_reg_value_snprintf_xml(char *buf, size_t size,
union nft_data_reg *reg, uint32_t flags)
{
int len = size, offset = 0, ret, i, j;
+ uint32_t be;
uint8_t *tmp;
- int data_len = reg->len/sizeof(uint32_t);
+ int data_len = reg->len/sizeof(reg->val[0]);
ret = snprintf(buf, len, "<data_reg type=\"value\">");
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
@@ -272,15 +274,17 @@ int nft_data_reg_value_snprintf_xml(char *buf, size_t size,
ret = snprintf(buf+offset, len, "<data%d>0x", i);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
- tmp = (uint8_t *)®->val[i];
+ be = htonl(reg->val[i]);
+ tmp = (uint8_t *)&be;
- for (j=0; j<sizeof(int); j++) {
+ for (j = 0; j < sizeof(uint32_t); j++) {
ret = snprintf(buf+offset, len, "%.02x", tmp[j]);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}
ret = snprintf(buf+offset, len, "</data%d>", i);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+
}
ret = snprintf(buf+offset, len, "</data_reg>");
next reply other threads:[~2013-06-03 20:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-03 20:44 Arturo Borrero [this message]
2013-06-03 20:44 ` [libnftables PATCH 2/5] rule: fix snprintf return value Arturo Borrero
2013-06-05 3:09 ` Pablo Neira Ayuso
2013-06-03 20:44 ` [libnftables PATCH 3/5] src: xml: set errno to EINVAL when invalid parsing Arturo Borrero
2013-06-05 3:38 ` Pablo Neira Ayuso
2013-06-03 20:44 ` [libnftables PATCH 4/5] expr: xml: don't print target&match info Arturo Borrero
2013-06-03 20:44 ` [libnftables PATCH 5/5] examples: get XML ruleset Arturo Borrero
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130603204451.27713.51887.stgit@nfdev.cica.es \
--to=arturo.borrero.glez@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.