From patchwork Sat May 2 10:11:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: michael-dev X-Patchwork-Id: 1281580 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=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netfilter-devel-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=fami-braun.de Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 49DlKC4mnRz9sRf for ; Sat, 2 May 2020 20:11:59 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727029AbgEBKLy (ORCPT ); Sat, 2 May 2020 06:11:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726574AbgEBKLy (ORCPT ); Sat, 2 May 2020 06:11:54 -0400 Received: from smail.fem.tu-ilmenau.de (smail.fem.tu-ilmenau.de [IPv6:2001:638:904:ffbf::41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF9A7C061A0C for ; Sat, 2 May 2020 03:11:53 -0700 (PDT) Received: from mail.fem.tu-ilmenau.de (mail-zuse.net.fem.tu-ilmenau.de [172.21.220.54]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smail.fem.tu-ilmenau.de (Postfix) with ESMTPS id D6AAF2010C; Sat, 2 May 2020 12:11:49 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.fem.tu-ilmenau.de (Postfix) with ESMTP id 92A7461FC; Sat, 2 May 2020 12:11:49 +0200 (CEST) X-Virus-Scanned: amavisd-new at fem.tu-ilmenau.de Received: from mail.fem.tu-ilmenau.de ([127.0.0.1]) by localhost (mail.fem.tu-ilmenau.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rDkEmT87Rimw; Sat, 2 May 2020 12:11:47 +0200 (CEST) Received: from mail-backup.fem.tu-ilmenau.de (mail-backup.net.fem.tu-ilmenau.de [10.42.40.22]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.fem.tu-ilmenau.de (Postfix) with ESMTPS; Sat, 2 May 2020 12:11:47 +0200 (CEST) Received: from a234.fem.tu-ilmenau.de (ray-controller.net.fem.tu-ilmenau.de [10.42.51.234]) by mail-backup.fem.tu-ilmenau.de (Postfix) with ESMTP id E1DAE56050; Sat, 2 May 2020 12:11:46 +0200 (CEST) Received: by a234.fem.tu-ilmenau.de (Postfix, from userid 1000) id B85A1306A950; Sat, 2 May 2020 12:11:46 +0200 (CEST) From: Michael Braun To: netfilter-devel@vger.kernel.org Cc: Michael Braun Subject: [PATCH] main: fix get_optstring truncating output Date: Sat, 2 May 2020 12:11:43 +0200 Message-Id: <20200502101143.18160-1-michael-dev@fami-braun.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Without this patch, get_optstring returns optstring = +hvVcf:insNSI:d:aejuy. After this patch, get_optstring returns optstring = +hvVcf:insNSI:d:aejuypTt This is due to optstring containing up to two chars per option, thus it was too short. Signed-off-by: Michael Braun --- src/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index d213c601..d830c7a2 100644 --- a/src/main.c +++ b/src/main.c @@ -118,7 +118,7 @@ static const struct nft_opt nft_options[] = { static const char *get_optstring(void) { - static char optstring[NR_NFT_OPTIONS + 2]; + static char optstring[2 * NR_NFT_OPTIONS + 2]; if (!optstring[0]) { size_t i, j; @@ -128,6 +128,8 @@ static const char *get_optstring(void) j += snprintf(optstring + j, sizeof(optstring) - j, "%c%s", nft_options[i].val, nft_options[i].arg ? ":" : ""); + + assert(j < sizeof(optstring)); } return optstring; }