From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f65.google.com (mail-lf0-f65.google.com [209.85.215.65]) by dpdk.org (Postfix) with ESMTP id 0D1A0FFA for ; Tue, 7 Feb 2017 03:51:24 +0100 (CET) Received: by mail-lf0-f65.google.com with SMTP id h65so5478941lfi.3 for ; Mon, 06 Feb 2017 18:51:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=32FDkYctpqhXPRGpP0n6C3xFvlWt4Iz2CSd8HWiDdCY=; b=qW6AShoYPkyEyCGMZ9/P1mPA+POkwgAqtxdHWPV4N8dd0unPUe/Y8ZdgpDdpffrF5e 81vwVKIZ7BsbIm6VPK7JCG/nBRcZGwgVUeeqno+u9jcLexRI4RZwPjgnZ90yYxG2OhkW 0TvjOCQi+7HzEqrc7KFffx7aouNm0mGmCmesJg1YIqHvyFuIj+QkPZqpHErViZIcI+5i hr71kdOaazK4IEyTWWnFzDc133wj8BgZMC800SRVzcc0Sr//G/ePe9mFYOYTxEzuB5Xy rbTd4BwGDIqOsQUUWZeA/akMoFX0KxCw+Ah9z0sbm9aEhNnXk6UJbd9yeqPkw0p/Jn8q Pf2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=32FDkYctpqhXPRGpP0n6C3xFvlWt4Iz2CSd8HWiDdCY=; b=RNkEuNifKLIhJC1ZxFBXIGxFGD+3Pxc1KB/OZfLVU4F8Q5LoZV74HyuQHt9nT3N5+p 0sjO64D471srA+JLtGag3GABELx9LoNA9RlpvBA83dW6PhCH0Wf1xpzP3bIQPUibbgDz NlXdzYDzA2hoeVRp3QBMXxoiYYBbeQE+jxZE/C9OSp9knuhAzyH+1UYYI7BG4B7seWdh CvneXtRKIfR3nMKUa3s+ANllV75qpqNMk5owOshC/mgyFeI/sVEou2etWv0GRTRD1LEn IqRfc951FNDLnLORZD7DeVZxdrKqaEkuJBRnROnzx2pDZRMuvz+jz7jKALuXi0QO1ZPq c23g== X-Gm-Message-State: AMke39kPclBP7jOCQcy8R8W2gguSFbrt8iTkJOpmdvspARLlu6xOgimjjgH9REhKHJjrNw== X-Received: by 10.25.156.144 with SMTP id f138mr5126255lfe.80.1486435884334; Mon, 06 Feb 2017 18:51:24 -0800 (PST) Received: from localhost.localdomain ([62.122.211.100]) by smtp.gmail.com with ESMTPSA id u18sm785682lff.48.2017.02.06.18.51.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Feb 2017 18:51:23 -0800 (PST) From: Dmitriy Yakovlev To: dev@dpdk.org Cc: Dmitriy Yakovlev Date: Tue, 7 Feb 2017 05:51:06 +0300 Message-Id: <1486435866-30562-1-git-send-email-bombermag@gmail.com> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH] cfgfile: fix uninitialized variable on load error X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Feb 2017 02:51:25 -0000 Uninitialized scalar variable. Using uninitialized value cfg->sections[curr_section]->num_entries when calling rte_cfgfile_close. And memory in variables cfg->sections[curr_section], sect->entries[curr_entry] maybe not equal NULL. We must decrement counters curr_section, curr_entry when failed to realloc. Fixes: eaafbad419bf ("cfgfile: library to interpret config files") Signed-off-by: Dmitriy Yakovlev --- lib/librte_cfgfile/rte_cfgfile.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index d72052a..829109a 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -151,6 +151,7 @@ struct rte_cfgfile * sizeof(*cfg) + sizeof(cfg->sections[0]) * allocated_sections); if (n_cfg == NULL) { + curr_section--; printf("Error - no more memory\n"); goto error1; } @@ -198,6 +199,7 @@ struct rte_cfgfile * sizeof(sect->entries[0]) * allocated_entries); if (n_sect == NULL) { + curr_entry--; printf("Error - no more memory\n"); goto error1; } @@ -233,6 +235,8 @@ struct rte_cfgfile * error1: cfg->num_sections = curr_section + 1; + if (curr_section >= 0) + cfg->sections[curr_section]->num_entries = curr_entry + 1; rte_cfgfile_close(cfg); error2: fclose(f); -- 1.9.1