From patchwork Mon Aug 17 09:38:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 40276 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E964385700C; Mon, 17 Aug 2020 09:38:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E964385700C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1597657122; bh=iKSrduVE9Uhi8/SneP7d6AO/OxRTw2WjBZcVPqOT30A=; h=Date:In-Reply-To:References:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Help:List-Subscribe:From:Reply-To:Cc:From; b=wthYwyN4oYLdPiDYHKnBPZZc50huY0cmw3KZrlz8haPbfCYijsSO2ODyk79Twe8JB CkkhT0j/tDkyfjC/XdcBcomaZDe5RjMTS2BnxdhwrHvEmoyynuNprJ8OWzYYqoRFci cHxgele6cP97qNWTER39BMSMwTcJs3Ob/Dj5q6VA= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) by sourceware.org (Postfix) with ESMTPS id 93B3E3858D37 for ; Mon, 17 Aug 2020 09:38:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 93B3E3858D37 Received: by mail-wm1-x349.google.com with SMTP id q15so5899477wmj.6 for ; Mon, 17 Aug 2020 02:38:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=iKSrduVE9Uhi8/SneP7d6AO/OxRTw2WjBZcVPqOT30A=; b=RKqY8WjpzBfxowCd5qop4gvGatuvWKM1btRhob7EFGrD5rMuSP+RDFlIBP9K+Diz4S Mi/9475HUcv2zK6cOucqqHw74hWPeY147kvptpsmt+1uEzzy/Qi11hIECJ4vKY+bK4Aj 8Qr7BK2hrnUlWSm4YM8vybzO/rvhVXt4eIEuA75sfkWjLRatPIilmlg+K5zBbO/hT922 /xAuEUhjFCskZtbswvlVet8RkIc5ntvMnBk4cDrSuNRw2zYfIqN4T2TF7H8DeSnxf18v Jyj57lH6ui0yd6nWiZqOBUw9aAE4GYQjnoMfa+r/qK4s6J4CO8qHJC/ZcdMZM/1jM7Oa E60A== X-Gm-Message-State: AOAM532k5W3UD/NTNoDEKOCekrpUoSr2fsIes9ovJUw4Z9Uj6mJsfSgu QcPmEyTK1ncSUACXXKPidM6Vhk7wP45IsDzupcsFoa1wlO3wD/O5I//Dd3Wa/daIWciCColFvUe sbWo6PjmOY7mNzJQgFAt9S8ByVGfVpUkhmvmlPBIcwCFYX6xMOkDSCt/NnJ1/DMrUJGZGSHs= X-Google-Smtp-Source: ABdhPJyx2+ORiG8agTcg9qYO0YepT+gAbwSMMRpWrElmBcDt+IqRvQ89OKSyOZwhAT4uvfGeI+mvwicGULo1iQ== X-Received: by 2002:a1c:2288:: with SMTP id i130mr13541874wmi.105.1597657118638; Mon, 17 Aug 2020 02:38:38 -0700 (PDT) Date: Mon, 17 Aug 2020 10:38:17 +0100 In-Reply-To: <20200817093819.172380-1-gprocida@google.com> Message-Id: <20200817093819.172380-6-gprocida@google.com> Mime-Version: 1.0 References: <20200817093819.172380-1-gprocida@google.com> X-Mailer: git-send-email 2.28.0.220.ged08abb693-goog Subject: [PATCH 5/7] Add error handling to read_suppressions. To: libabigail@sourceware.org X-Spam-Status: No, score=-22.6 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Giuliano Procida via Libabigail From: Giuliano Procida Reply-To: Giuliano Procida Cc: kernel-team@android.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" The top-level parsing functions read_suppresions (one file-scoped overload and two externally-visible overloads) have no error handling. This change makes each return a success status and adds placeholders for where error messages might be emitted. There are no behavioural changes. * include/abg-suppression.h (read_suppresions): Change return type to bool. * src/abg-suppression.cc (read_suppresions): In the static worker overload, return parse success status. In the wrapper overloads return false if ini config parsing fails. Signed-off-by: Giuliano Procida --- include/abg-suppression.h | 4 +-- src/abg-suppression.cc | 57 +++++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/include/abg-suppression.h b/include/abg-suppression.h index 6383b9322..dbb52de35 100644 --- a/include/abg-suppression.h +++ b/include/abg-suppression.h @@ -130,11 +130,11 @@ public: const suppression_base& suppr); }; // end class suppression_base -void +bool read_suppressions(std::istream& input, suppressions_type& suppressions); -void +bool read_suppressions(const string& file_path, suppressions_type& suppressions); diff --git a/src/abg-suppression.cc b/src/abg-suppression.cc index 736c7f51f..fb97a124b 100644 --- a/src/abg-suppression.cc +++ b/src/abg-suppression.cc @@ -372,10 +372,12 @@ read_file_suppression(const ini::config::section& section, /// /// @param suppressions out parameter. The vector of suppressions to /// append the newly read suppressions to. -static void -read_suppressions(const ini::config& config, - suppressions_type& suppressions) +/// +/// @return whether the parse was successful. +static bool +read_suppressions(const ini::config& config, suppressions_type& suppressions) { + bool success = true; for (ini::config::sections_type::const_iterator i = config.get_sections().begin(); i != config.get_sections().end(); @@ -383,18 +385,31 @@ read_suppressions(const ini::config& config, { const ini::config::section_sptr& section = *i; const std::string& name = section->get_name(); + bool section_success; suppression_sptr s; if (name == "suppress_type") - read_type_suppression(*section, s); + section_success = read_type_suppression(*section, s); else if (name == "suppress_function") - read_function_suppression(*section, s); + section_success = read_function_suppression(*section, s); else if (name == "suppress_variable") - read_variable_suppression(*section, s); + section_success = read_variable_suppression(*section, s); else if (name == "suppress_file") - read_file_suppression(*section, s); - if (s) + section_success = read_file_suppression(*section, s); + else + { + // TODO: maybe emit unknown section name error + success = false; + continue; + } + if (section_success) suppressions.push_back(s); + else + { + // TODO: maybe emit section parse failure message + success = false; + } } + return success; } /// Read suppressions specifications from an input stream. @@ -403,12 +418,19 @@ read_suppressions(const ini::config& config, /// /// @param suppressions the vector of suppressions to append the newly /// read suppressions to. -void +/// +/// @return whether the parse was successful +bool read_suppressions(std::istream& input, suppressions_type& suppressions) { - if (ini::config_sptr config = ini::read_config(input)) - read_suppressions(*config, suppressions); + ini::config_sptr config = ini::read_config(input); + if (!config) + { + // TODO: maybe report ini configuration parse failure + return false; + } + return read_suppressions(*config, suppressions); } /// Read suppressions specifications from an input file on disk. @@ -417,12 +439,19 @@ read_suppressions(std::istream& input, /// /// @param suppressions the vector of suppressions to append the newly /// read suppressions to. -void +/// +/// @return whether the parse was successful +bool read_suppressions(const string& file_path, suppressions_type& suppressions) { - if (ini::config_sptr config = ini::read_config(file_path)) - read_suppressions(*config, suppressions); + ini::config_sptr config = ini::read_config(file_path); + if (!config) + { + // TODO: maybe report ini configuration file_path parse failure + return false; + } + return read_suppressions(*config, suppressions); } //