auto-cleaning of strings for types that cannot contain chars < 0x20 by design

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8547 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-06-23 19:25:13 +00:00
parent f7e147c35d
commit e1dcdd78b6

View File

@ -579,6 +579,33 @@ bool GetTlvString(void *data, uint32_t size, uint32_t *offset,
break ; break ;
} }
// Also check that the string does not contain invalid characters.
// Every character less than 0x20 will be turned into a space (0x20).
// This is compatible with utf8, as all utf8 chars are > 0x7f.
// We do this for strings that should not contain some
// special characters by design.
if( type == 0 // this is used for mGroupName and mMsgName
|| type == TLV_TYPE_STR_PEERID
|| type == TLV_TYPE_STR_NAME
|| type == TLV_TYPE_STR_PATH
|| type == TLV_TYPE_STR_TITLE
|| type == TLV_TYPE_STR_SUBJECT
|| type == TLV_TYPE_STR_LOCATION
|| type == TLV_TYPE_STR_VERSION )
{
bool modified = false ;
for(uint32_t i=0;i<in.length();++i)
if(in[i] < 0x20 && in[i] > 0)
{
modified = true ;
in[i] = 0x20 ;
}
if(modified)
std::cerr << "(WW) De-serialised string of type " << type << " contains forbidden characters. They have been replaced by spaces. New string: \"" << in << "\"" << std::endl;
}
*offset += tlvsize; /* step along */ *offset += tlvsize; /* step along */
return true; return true;
} }