Fixed off-by-one error in 'name' of add_note() function.

Previously, when assigning 'name' as a string, it's length was specified
using the full length of 'namesz'. However, this length includes the
trailing '\0' of the underlying char[]. This ultimately causes the C++
string that is created to (incorrectly) contain the '\0' character as
well. This leads to problems where e.g. the following will return false,
even when 'name' itself actually contains the string "GNU\0":

  if (name == "GNU") {
    return true;
  }
  return false;

To fix this, we should only include the length of the string minus the
trailing '\0'.
This commit is contained in:
Kevin Klues 2016-07-02 10:17:44 -07:00
parent 8e7a29e128
commit e3e0d6dbdb

View File

@ -66,7 +66,7 @@ class note_section_accessor
namesz + descSize > max_name_size ) {
return false;
}
name.assign( pData + 3 * sizeof( Elf_Word ), namesz );
name.assign( pData + 3 * sizeof( Elf_Word ), namesz - 1);
if ( 0 == descSize ) {
desc = 0;
}