Bug 19434 - invalid character in attribute value

* include/abg-tools-utils.h (string_is_ascii_identifier): Declare
	new function.
	* src/abg-tools-utils.cc (string_is_ascii_identifier): Define new function.
	* src/abg-dwarf-reader.cc (build_function_type): Discard parameter
	name if it's made of non-identifier ascii characters.
	* tests/data/test-types-stability/pr19434-elf0: New test binary input file.
	* tests/data/Makefile.am: Add the new test input to source distribution.
	* tests/test-types-stability.cc: Test the new test input into account.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Dodji Seketeli 2016-01-13 15:34:42 +01:00
parent 5e171c530c
commit c3869ecc7b
6 changed files with 36 additions and 1 deletions

View File

@ -50,6 +50,7 @@ bool ensure_parent_dir_created(const string&);
bool check_file(const string& path, ostream& out);
bool string_ends_with(const string&, const string&);
bool string_is_ascii(const string&);
bool string_is_ascii_identifier(const string&);
class temp_file;

View File

@ -7559,7 +7559,7 @@ build_function_type(read_context& ctxt,
string name, linkage_name;
location loc;
die_loc_and_name(ctxt, &child, loc, name, linkage_name);
if (!tools_utils::string_is_ascii(name))
if (!tools_utils::string_is_ascii_identifier(name))
// Sometimes, bogus compiler emit names that are
// non-ascii garbage. Let's just ditch that for now.
name.clear();

View File

@ -347,6 +347,38 @@ string_is_ascii(const string& str)
return true;
}
/// Test if a string is made of ascii characters which are identifiers
/// acceptable in C or C++ programs.
///
///
/// In the C++ spec, [lex.charset]/2, we can read:
///
/// "if the hexadecimal value for a universal-character-name [...] or
/// string literal corresponds to a control character (in either of
/// the ranges 0x000x1F or 0x7F0x9F, both inclusive) [...] the
/// program is ill-formed."
///
/// @param str the string to consider.
///
/// @return true iff @p str is made of ascii characters, and is an
/// identifier.
bool
string_is_ascii_identifier(const string& str)
{
for (string::const_iterator i = str.begin(); i != str.end(); ++i)
{
unsigned char c = *i;
if (!isascii(c)
|| (c <= 0x1F) // Rule out control characters
|| (c >= 0x7F && c <= 0x9F)) // Rule out special extended
// ascii characters.
return false;
}
return true;
}
/// The private data of the @ref temp_file type.
struct temp_file::priv
{

View File

@ -314,6 +314,7 @@ test-read-dwarf/test21-pr19092.so.abi \
test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so \
test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi \
\
test-types-stability/pr19434-elf0 \
test-types-stability/pr19139-DomainNeighborMapInst.o \
test-types-stability/pr19202-libmpi_gpfs.so.5.0 \
test-types-stability/pr19026-libvtkIOSQL-6.1.so.1 \

Binary file not shown.

View File

@ -53,6 +53,7 @@ using std::cerr;
// A set of elf files to test type stability for.
const char* elf_paths[] =
{
"data/test-types-stability/pr19434-elf0",
"data/test-types-stability/pr19139-DomainNeighborMapInst.o",
"data/test-types-stability/pr19202-libmpi_gpfs.so.5.0",
"data/test-types-stability/pr19026-libvtkIOSQL-6.1.so.1",