[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Undefined behaviour in abigail::tool_utils::string_ends_with.
Hi Doji,
Currently string_ends_with will crash if the suffix is longer than the
string. I've attached a patch that fixes this bug.
I discovered the bug by running abicompat ./a.out <lib1> <lib2>. This
command crashed because guess_file_type will call
string_ends_with("./a.out", ".tar.gz").
/Eric
diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc
index 060c6c3..f255023 100644
--- a/src/abg-tools-utils.cc
+++ b/src/abg-tools-utils.cc
@@ -324,6 +324,7 @@ check_file(const string& path,
bool
string_ends_with(const string& str, const string& suffix)
{
+ if (suffix.length() > str.length()) return false;
return str.compare(str.length() - suffix.length(),
suffix.length(),
suffix) == 0;