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 ) 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 // break text at predefined position, if text is too short, break anyway to
// make sure we have two lines for fader tag // make sure we have two lines for fader tag

View File

@ -37,10 +37,23 @@ CChatDlg::CChatDlg ( QWidget* parent, Qt::WindowFlags f ) :
// Connections ------------------------------------------------------------- // Connections -------------------------------------------------------------
QObject::connect ( lineEditLocalInputText, SIGNAL ( textChanged ( const QString& ) ),
this, SLOT ( OnChatTextChanged ( const QString& ) ) );
QObject::connect ( lineEditLocalInputText, SIGNAL ( returnPressed() ), QObject::connect ( lineEditLocalInputText, SIGNAL ( returnPressed() ),
this, SLOT ( OnNewLocalInputText() ) ); 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() void CChatDlg::OnNewLocalInputText()
{ {
// send new text and clear line afterwards // send new text and clear line afterwards

View File

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

View File

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

View File

@ -121,6 +121,13 @@
// length of the moving average buffer for response time measurement // length of the moving average buffer for response time measurement
#define TIME_MOV_AV_RESPONSE 30 // seconds #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 _MAXSHORT 32767
#define _MAXBYTE 255 // binary: 11111111 #define _MAXBYTE 255 // binary: 11111111

View File

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

View File

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

View File

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