From patchwork Wed Jun 26 11:37:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arturo Borrero X-Patchwork-Id: 254722 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 16C9B2C0092 for ; Wed, 26 Jun 2013 21:37:41 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752193Ab3FZLhi (ORCPT ); Wed, 26 Jun 2013 07:37:38 -0400 Received: from smtp3.cica.es ([150.214.5.190]:54697 "EHLO smtp.cica.es" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752091Ab3FZLhV (ORCPT ); Wed, 26 Jun 2013 07:37:21 -0400 Received: from localhost (unknown [127.0.0.1]) by smtp.cica.es (Postfix) with ESMTP id 8086D51ED34; Wed, 26 Jun 2013 11:37:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at cica.es Received: from smtp.cica.es ([127.0.0.1]) by localhost (mail.cica.es [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hjdzFuOJHhPi; Wed, 26 Jun 2013 13:37:15 +0200 (CEST) Received: from nfdev.cica.es (nfdev.cica.es [IPv6:2a00:9ac0:c1ca:31::220]) by smtp.cica.es (Postfix) with ESMTP id 5597251ED31; Wed, 26 Jun 2013 13:37:15 +0200 (CEST) Subject: [libnftables PATCH 14/21] data_reg: xml: fix bytes movements To: netfilter-devel@vger.kernel.org From: Arturo Borrero Gonzalez Cc: pablo@netfilter.org Date: Wed, 26 Jun 2013 13:37:13 +0200 Message-ID: <20130626113713.23511.47779.stgit@nfdev.cica.es> In-Reply-To: <20130626113509.23511.14359.stgit@nfdev.cica.es> References: <20130626113509.23511.14359.stgit@nfdev.cica.es> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Fix wrong arithmetics when printing and parsing data registers in XML: Previous to this patch, a uin32_t containing the number 2864434397 (0xaabbccdd) will be printed this way under some circumstances: 0xddccbbaa Now, the data is ordered, the MSB position is controlled and snprintf prints: 0xaabbccdd Signed-off-by: Arturo Borrero Gonzalez --- src/expr/data_reg.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c index b8b8d66..c123d88 100644 --- a/src/expr/data_reg.c +++ b/src/expr/data_reg.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -205,7 +206,6 @@ static int nft_data_reg_value_xml_parse(union nft_data_reg *reg, char *xml) reg->val[i] = utmp; } - mxmlDelete(tree); return 0; } @@ -258,6 +258,7 @@ 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); @@ -271,9 +272,10 @@ int nft_data_reg_value_snprintf_xml(char *buf, size_t size, ret = snprintf(buf+offset, len, "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