From patchwork Wed May 18 12:06:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 9118281 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 926A59F30C for ; Wed, 18 May 2016 12:20:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EBAD920154 for ; Wed, 18 May 2016 12:20:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3AFB920138 for ; Wed, 18 May 2016 12:20:42 +0000 (UTC) Received: from localhost ([::1]:44554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b30Sv-0005dv-CZ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 18 May 2016 08:20:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b30Mo-00006F-PP for qemu-devel@nongnu.org; Wed, 18 May 2016 08:14:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b30Mk-00030m-Gq for qemu-devel@nongnu.org; Wed, 18 May 2016 08:14:21 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:49470) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b30Mk-00030Q-93; Wed, 18 May 2016 08:14:18 -0400 Received: from tsrv.tls.msk.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 02ED3417A0; Wed, 18 May 2016 15:14:17 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.tls.msk.ru (Postfix) with SMTP id AC5D7AE2; Wed, 18 May 2016 15:06:11 +0300 (MSK) Received: (nullmailer pid 12392 invoked by uid 1000); Wed, 18 May 2016 12:06:09 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Wed, 18 May 2016 15:06:01 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 86.62.121.231 Subject: [Qemu-devel] [PULL 06/13] qdict: fix unbounded stack warning for qdict_array_entries X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, Michael Tokarev , Peter Xu Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Peter Xu Here we use one g_strdup_printf() to replace the two stack allocated array, considering it's more convenient, safe, and as long as it's called rarely only when quorum device opens. This will remove the unbound stack warning when compiling with "-Wstack-usage=1000000". Reviewed-by: Eric Blake Signed-off-by: Peter Xu Reviewed-by: Markus Armbruster Signed-off-by: Michael Tokarev --- qobject/qdict.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/qobject/qdict.c b/qobject/qdict.c index a128536..60f158c 100644 --- a/qobject/qdict.c +++ b/qobject/qdict.c @@ -705,19 +705,16 @@ int qdict_array_entries(QDict *src, const char *subqdict) for (i = 0; i < INT_MAX; i++) { QObject *subqobj; int subqdict_entries; - size_t slen = 32 + subqdict_len; - char indexstr[slen], prefix[slen]; - size_t snprintf_ret; + char *prefix = g_strdup_printf("%s%u.", subqdict, i); - snprintf_ret = snprintf(indexstr, slen, "%s%u", subqdict, i); - assert(snprintf_ret < slen); + subqdict_entries = qdict_count_prefixed_entries(src, prefix); - subqobj = qdict_get(src, indexstr); + /* Remove ending "." */ + prefix[strlen(prefix) - 1] = 0; + subqobj = qdict_get(src, prefix); - snprintf_ret = snprintf(prefix, slen, "%s%u.", subqdict, i); - assert(snprintf_ret < slen); + g_free(prefix); - subqdict_entries = qdict_count_prefixed_entries(src, prefix); if (subqdict_entries < 0) { return subqdict_entries; }