From patchwork Wed Oct 4 12:23:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 821289 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3y6ZnH2yCmz9t16 for ; Wed, 4 Oct 2017 23:23:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751916AbdJDMXa (ORCPT ); Wed, 4 Oct 2017 08:23:30 -0400 Received: from mail.us.es ([193.147.175.20]:42370 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751699AbdJDMX3 (ORCPT ); Wed, 4 Oct 2017 08:23:29 -0400 Received: from antivirus1-rhel7.int (unknown [192.168.2.11]) by mail.us.es (Postfix) with ESMTP id 7B1B31DA087 for ; Wed, 4 Oct 2017 14:23:28 +0200 (CEST) Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id 6CF48DA86B for ; Wed, 4 Oct 2017 14:23:28 +0200 (CEST) Received: by antivirus1-rhel7.int (Postfix, from userid 99) id 6C3F3DA86C; Wed, 4 Oct 2017 14:23:28 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on antivirus1-rhel7.int X-Spam-Level: X-Spam-Status: No, score=-108.2 required=7.5 tests=ALL_TRUSTED,BAYES_50, SMTPAUTH_US2,USER_IN_WHITELIST autolearn=disabled version=3.4.1 Received: from antivirus1-rhel7.int (localhost [127.0.0.1]) by antivirus1-rhel7.int (Postfix) with ESMTP id 4F206DA86B for ; Wed, 4 Oct 2017 14:23:26 +0200 (CEST) Received: from 192.168.1.97 (192.168.1.97) by antivirus1-rhel7.int (F-Secure/fsigk_smtp/550/antivirus1-rhel7.int); Wed, 04 Oct 2017 14:23:26 +0200 (CEST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/antivirus1-rhel7.int) Received: from salvia.here (129.166.216.87.static.jazztel.es [87.216.166.129]) (Authenticated sender: pneira@us.es) by entrada.int (Postfix) with ESMTPA id 17ADF40584CE for ; Wed, 4 Oct 2017 14:23:26 +0200 (CEST) X-SMTPAUTHUS: auth mail.us.es From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Subject: [PATCH libnftnl, v2 1/4] buffer: use nftnl_expr_snprintf() from nftnl_buf_expr() Date: Wed, 4 Oct 2017 14:23:20 +0200 Message-Id: <1507119803-15127-1-git-send-email-pablo@netfilter.org> X-Mailer: git-send-email 2.1.4 X-Virus-Scanned: ClamAV using ClamSMTP Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org This helper function deals with no ->snprintf() indirection in expression and safe buffer nul-termination, use it. Fixes: 059b9bf6fb31 ("src: Use nftnl_buf to export XML/JSON rules") Signed-off-by: Pablo Neira Ayuso --- src/buffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index f9d5a838c4ab..9ec86af121c9 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "internal.h" int nftnl_buf_update(struct nftnl_buf *b, int ret) @@ -206,8 +207,8 @@ int nftnl_buf_expr(struct nftnl_buf *b, int type, uint32_t flags, case NFTNL_OUTPUT_JSON: nftnl_buf_put(b, "{"); nftnl_buf_str(b, type, expr->ops->name, TYPE); - ret = expr->ops->snprintf(b->buf + b->off, b->len, type, flags, - expr); + ret = nftnl_expr_snprintf(b->buf + b->off, b->len, expr, type, + flags); if (ret > 0) nftnl_buf_update(b, ret); else