* [PATCH] Fix --type-id-style hash for empty internal names.
@ 2020-07-06 9:21 Giuliano Procida
2020-07-10 16:00 ` Matthias Maennich
2020-07-27 9:48 ` Dodji Seketeli
0 siblings, 2 replies; 3+ messages in thread
From: Giuliano Procida @ 2020-07-06 9:21 UTC (permalink / raw)
To: libabigail; +Cc: dodji, kernel-team, gprocida, maennich
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 <gprocida@google.com>
---
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();
--
2.27.0.212.ge8ba1cc988-goog
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix --type-id-style hash for empty internal names.
2020-07-06 9:21 [PATCH] Fix --type-id-style hash for empty internal names Giuliano Procida
@ 2020-07-10 16:00 ` Matthias Maennich
2020-07-27 9:48 ` Dodji Seketeli
1 sibling, 0 replies; 3+ messages in thread
From: Matthias Maennich @ 2020-07-10 16:00 UTC (permalink / raw)
To: Giuliano Procida; +Cc: libabigail, dodji, kernel-team
On Mon, Jul 06, 2020 at 10:21:33AM +0100, Giuliano Procida wrote:
>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.
>
Reviewed-by: Matthias Maennich <maennich@google.com>
Cheers,
Matthias
>Signed-off-by: Giuliano Procida <gprocida@google.com>
>---
> 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;
could be const
>+ 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();
>--
>2.27.0.212.ge8ba1cc988-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix --type-id-style hash for empty internal names.
2020-07-06 9:21 [PATCH] Fix --type-id-style hash for empty internal names Giuliano Procida
2020-07-10 16:00 ` Matthias Maennich
@ 2020-07-27 9:48 ` Dodji Seketeli
1 sibling, 0 replies; 3+ messages in thread
From: Dodji Seketeli @ 2020-07-27 9:48 UTC (permalink / raw)
To: Giuliano Procida; +Cc: libabigail, kernel-team, maennich
Giuliano Procida <gprocida@google.com> a écrit:
[...]
> +++ 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);
This should work:
size_t hash = hashing::fnv_hash(pretty);
And we'd do away with the line above:
+ std::string str = pretty;
[...]
> + 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();
Applied with the above change.
Thanks!
Cheers,
--
Dodji
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-27 9:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-06 9:21 [PATCH] Fix --type-id-style hash for empty internal names Giuliano Procida
2020-07-10 16:00 ` Matthias Maennich
2020-07-27 9:48 ` Dodji Seketeli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).