From patchwork Mon Jul 6 09:21:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Giuliano Procida X-Patchwork-Id: 39916 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 DD6A93858D35; Mon, 6 Jul 2020 09:21:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD6A93858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1594027299; bh=A5HBwaccg/X8dIxr0o3+hVYh2MezaWuW4mJ0CbRH3bg=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=s2tfV9622WDaH1M7qXgx4sapgQ+ZDI2LL2kkDC9LXgU30z8oQWtIG5fPKLJwQrOAm /qRTsmaHCG8u6TTQxercr3dDJZ1eS2HYyVJryf+FTjK2S2B76/6/IUloYlaFaW9jiw 0shfGAxyVjrU20kEkN8BxvzaBmfCBrlGlkZswnzg= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by sourceware.org (Postfix) with ESMTPS id 486DC3858D35 for ; Mon, 6 Jul 2020 09:21:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 486DC3858D35 Received: by mail-wr1-x449.google.com with SMTP id j3so21803476wrq.9 for ; Mon, 06 Jul 2020 02:21:38 -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:message-id:mime-version:subject:from:to:cc; bh=A5HBwaccg/X8dIxr0o3+hVYh2MezaWuW4mJ0CbRH3bg=; b=d7qVarzZQlnIqpIsSQu7OxXacZFJM6tDfddsHCjnubKsBQe+noEj/TxZ5mHox5lDKC guZEJvm4pDisgTdRnCnC5WAeftkagokgmoMIZMbpXyXh9LkBiPE7b8PskzZNHkpUeSej yOl8qrhKQRKSDGmVP5SZ6EWFIGJBrkgnH9muRXtWLeaumXgYfxVMVx5hJnklQEuSsU54 v8Hs+OX9nz+NwEvVWCyP6bOBc1J1RcTkkhpmcSYt8PewvcsfoeioW2HlM9CDlBtn7hfC aFt3JcIwFGyO/sS2J2WboHsXRboPdMQw8oeEPgPy4kGDdLiigxQycHYpS8W+HqX3Qg9r SP+g== X-Gm-Message-State: AOAM531RSJYZVj+IdSzJDvGYHUNCB5R+XHUkm3AE0zIrHyWC1Q67ABoZ N6RkeIETQEY5M0cbSaOx8BSQZS9v7EGaj7EdJIMDk94dCsJ0TAZlNCUyXh7GYk135pO3QloNLdR gHghPDfSI1LrET7t4bBv5nYTzHgNX4rF7ttboZWUNRUReOXvZWBOKXfZpl9RngzDGMyqldQw= X-Google-Smtp-Source: ABdhPJzsIQoruNoBs8PTWPKA3v7zlxpCwGsjoF6hfh2RPp3cdD9nhG5wr7llG9n4aXlmjzuua5EHAs6MofC7yQ== X-Received: by 2002:a1c:cc09:: with SMTP id h9mr531771wmb.1.1594027296418; Mon, 06 Jul 2020 02:21:36 -0700 (PDT) Date: Mon, 6 Jul 2020 10:21:33 +0100 Message-Id: <20200706092133.287078-1-gprocida@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog Subject: [PATCH] Fix --type-id-style hash for empty internal names. To: libabigail@sourceware.org X-Spam-Status: No, score=-23.8 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: maennich@google.com, kernel-team@android.com Errors-To: libabigail-bounces@sourceware.org Sender: "Libabigail" libabigail's intern_string class treats the empty string specially. It is not safe to call the raw method without checking for a empty pointer. It is safe to convert to std::string. This commit changes the XML writer to convert interned strings to std::strings before computing their hashes. * src/abg-writer.cc (write_context::get_id_for_type): When hashing internal type names, convert to std::string rather than using the raw method directly as this will avoid a null pointer dereference in the case of an empty string; tabify code indentation. Signed-off-by: Giuliano Procida Reviewed-by: Matthias Maennich --- src/abg-writer.cc | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/abg-writer.cc b/src/abg-writer.cc index ce0bae2d..b9813ef4 100644 --- a/src/abg-writer.cc +++ b/src/abg-writer.cc @@ -450,20 +450,21 @@ public: switch (m_type_id_style) { case SEQUENCE_TYPE_ID_STYLE: - { - interned_string id = get_id_manager().get_id_with_prefix("type-id-"); - return m_type_id_map[c] = id; - } + { + interned_string id = get_id_manager().get_id_with_prefix("type-id-"); + return m_type_id_map[c] = id; + } case HASH_TYPE_ID_STYLE: - { - interned_string pretty = c->get_cached_pretty_representation(true); - size_t hash = hashing::fnv_hash(*pretty.raw()); - while (!m_used_type_id_hashes.insert(hash).second) - ++hash; - std::ostringstream os; - os << std::hex << std::setfill('0') << std::setw(8) << hash; - return m_type_id_map[c] = c->get_environment()->intern(os.str()); - } + { + interned_string pretty = c->get_cached_pretty_representation(true); + std::string str = pretty; + size_t hash = hashing::fnv_hash(str); + while (!m_used_type_id_hashes.insert(hash).second) + ++hash; + std::ostringstream os; + os << std::hex << std::setfill('0') << std::setw(8) << hash; + return m_type_id_map[c] = c->get_environment()->intern(os.str()); + } } ABG_ASSERT_NOT_REACHED; return interned_string();