implement checks for string sizes

This commit is contained in:
Volker Fischer 2009-10-26 21:10:14 +00:00
parent c0685e9b78
commit f3c5b69aba
8 changed files with 50 additions and 27 deletions

View file

@ -230,7 +230,7 @@ void CChannelFader::SetOtherSoloState ( const bool bState )
void CChannelFader::SetText ( const QString sText )
{
const int iBreakPos = 8;
const int iBreakPos = MAX_LEN_FADER_TAG / 2;
// break text at predefined position, if text is too short, break anyway to
// make sure we have two lines for fader tag

View file

@ -37,10 +37,23 @@ CChatDlg::CChatDlg ( QWidget* parent, Qt::WindowFlags f ) :
// Connections -------------------------------------------------------------
QObject::connect ( lineEditLocalInputText, SIGNAL ( textChanged ( const QString& ) ),
this, SLOT ( OnChatTextChanged ( const QString& ) ) );
QObject::connect ( lineEditLocalInputText, SIGNAL ( returnPressed() ),
this, SLOT ( OnNewLocalInputText() ) );
}
void CChatDlg::OnChatTextChanged ( const QString& strNewText )
{
// check and correct length
if ( strNewText.length() > MAX_LEN_CHAT_TEXT )
{
// text is too long, update control with shortend text
lineEditLocalInputText->setText ( strNewText.left ( MAX_LEN_CHAT_TEXT ) );
}
}
void CChatDlg::OnNewLocalInputText()
{
// send new text and clear line afterwards

View file

@ -48,6 +48,7 @@ public:
public slots:
void OnNewLocalInputText();
void OnChatTextChanged ( const QString& strNewText );
signals:
void NewLocalInputText ( QString strNewText );

View file

@ -29,11 +29,7 @@
<widget class="QTextBrowser" name="TextViewChatWindow" />
</item>
<item>
<widget class="QLineEdit" name="lineEditLocalInputText" >
<property name="maxLength" >
<number>255</number>
</property>
</widget>
<widget class="QLineEdit" name="lineEditLocalInputText" />
</item>
<item>
<layout class="QHBoxLayout" >

View file

@ -121,6 +121,13 @@
// length of the moving average buffer for response time measurement
#define TIME_MOV_AV_RESPONSE 30 // seconds
// Maximum length of fader tag and text message strings (Since for chat messages
// some HTML code is added, we also have to define a second length which includes
// this additionl HTML code. Right now the length of the HTML code is approx. 66
// character. Here, we add some headroom to this number)
#define MAX_LEN_FADER_TAG 16
#define MAX_LEN_CHAT_TEXT 1600
#define MAX_LEN_CHAT_TEXT_PLUS_HTML 1800
#define _MAXSHORT 32767
#define _MAXBYTE 255 // binary: 11111111

View file

@ -493,11 +493,20 @@ void CLlconClientDlg::ShowChatWindow()
void CLlconClientDlg::OnFaderTagTextChanged ( const QString& strNewName )
{
// refresh internal name parameter
pClient->strName = strNewName;
// check length
if ( strNewName.length() <= MAX_LEN_FADER_TAG )
{
// refresh internal name parameter
pClient->strName = strNewName;
// update name at server
pClient->SetRemoteName();
// update name at server
pClient->SetRemoteName();
}
else
{
// text is too long, update control with shortend text
LineEditFaderTag->setText ( strNewName.left ( MAX_LEN_FADER_TAG ) );
}
}
void CLlconClientDlg::OnTimerSigMet()

View file

@ -120,11 +120,7 @@
</widget>
</item>
<item row="3" column="1" >
<widget class="QLineEdit" name="LineEditFaderTag" >
<property name="maxLength" >
<number>16</number>
</property>
</widget>
<widget class="QLineEdit" name="LineEditFaderTag" />
</item>
</layout>
</item>

View file

@ -670,11 +670,11 @@ void CProtocol::CreateChanNameMes ( const QString strName )
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iStrLen ), 2 );
// name string (n bytes)
for ( int j = 0; j < iStrLen; j++ )
for ( int i = 0; i < iStrLen; i++ )
{
// byte-by-byte copying of the string data
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( strName[j].toAscii() ), 1 );
static_cast<uint32_t> ( strName[i].toAscii() ), 1 );
}
CreateAndSendMessage ( PROTMESSID_CHANNEL_NAME, vecData );
@ -695,14 +695,14 @@ bool CProtocol::EvaluateChanNameMes ( const CVector<uint8_t>& vecData )
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
// check size
if ( vecData.Size() - 2 != iStrLen )
if ( ( vecData.Size() - 2 != iStrLen ) || ( iStrLen > MAX_LEN_FADER_TAG ) )
{
return true;
}
// name string (n bytes)
QString strName = "";
for ( int j = 0; j < iStrLen; j++ )
for ( int i = 0; i < iStrLen; i++ )
{
// byte-by-byte copying of the string data
int iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
@ -739,15 +739,15 @@ void CProtocol::CreateChatTextMes ( const QString strChatText )
// build data vector
CVector<uint8_t> vecData ( iEntrLen );
// number of bytes for name string (2 bytes)
// number of bytes for chat text string (2 bytes)
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iStrLen ), 2 );
// name string (n bytes)
for ( int j = 0; j < iStrLen; j++ )
// chat text string (n bytes)
for ( int i = 0; i < iStrLen; i++ )
{
// byte-by-byte copying of the string data
PutValOnStream ( vecData, iPos,
static_cast<uint32_t> ( strChatText[j].toAscii() ), 1 );
static_cast<uint32_t> ( strChatText[i].toAscii() ), 1 );
}
CreateAndSendMessage ( PROTMESSID_CHAT_TEXT, vecData );
@ -763,19 +763,20 @@ bool CProtocol::EvaluateChatTextMes ( const CVector<uint8_t>& vecData )
return true;
}
// number of bytes for name string (2 bytes)
// number of bytes for chat text string (2 bytes)
const int iStrLen =
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
// check size
if ( vecData.Size() - 2 != iStrLen )
if ( ( vecData.Size() - 2 != iStrLen ) ||
( iStrLen > MAX_LEN_CHAT_TEXT_PLUS_HTML ) )
{
return true;
}
// name string (n bytes)
// chat text string (n bytes)
QString strChatText = "";
for ( int j = 0; j < iStrLen; j++ )
for ( int i = 0; i < iStrLen; i++ )
{
// byte-by-byte copying of the string data
int iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );