From f3c5b69abafa8dad30c7bacb12b6633ef8269234 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Mon, 26 Oct 2009 21:10:14 +0000 Subject: [PATCH] implement checks for string sizes --- src/audiomixerboard.cpp | 2 +- src/chatdlg.cpp | 13 +++++++++++++ src/chatdlg.h | 1 + src/chatdlgbase.ui | 6 +----- src/global.h | 7 +++++++ src/llconclientdlg.cpp | 17 +++++++++++++---- src/llconclientdlgbase.ui | 6 +----- src/protocol.cpp | 25 +++++++++++++------------ 8 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/audiomixerboard.cpp b/src/audiomixerboard.cpp index 3cbf1b82..bca80a44 100755 --- a/src/audiomixerboard.cpp +++ b/src/audiomixerboard.cpp @@ -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 diff --git a/src/chatdlg.cpp b/src/chatdlg.cpp index 0e365748..98bd4531 100755 --- a/src/chatdlg.cpp +++ b/src/chatdlg.cpp @@ -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 diff --git a/src/chatdlg.h b/src/chatdlg.h index 0f2d6f14..eba87f89 100755 --- a/src/chatdlg.h +++ b/src/chatdlg.h @@ -48,6 +48,7 @@ public: public slots: void OnNewLocalInputText(); + void OnChatTextChanged ( const QString& strNewText ); signals: void NewLocalInputText ( QString strNewText ); diff --git a/src/chatdlgbase.ui b/src/chatdlgbase.ui index 6542b629..facd372b 100755 --- a/src/chatdlgbase.ui +++ b/src/chatdlgbase.ui @@ -29,11 +29,7 @@ - - - 255 - - + diff --git a/src/global.h b/src/global.h index eeb6eaa5..21f6c834 100755 --- a/src/global.h +++ b/src/global.h @@ -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 diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index 6dd131c7..61c3240f 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -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() diff --git a/src/llconclientdlgbase.ui b/src/llconclientdlgbase.ui index 2eb28ca2..e41816e3 100755 --- a/src/llconclientdlgbase.ui +++ b/src/llconclientdlgbase.ui @@ -120,11 +120,7 @@ - - - 16 - - + diff --git a/src/protocol.cpp b/src/protocol.cpp index 9b01f4ed..fd37963f 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -670,11 +670,11 @@ void CProtocol::CreateChanNameMes ( const QString strName ) PutValOnStream ( vecData, iPos, static_cast ( 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 ( strName[j].toAscii() ), 1 ); + static_cast ( strName[i].toAscii() ), 1 ); } CreateAndSendMessage ( PROTMESSID_CHANNEL_NAME, vecData ); @@ -695,14 +695,14 @@ bool CProtocol::EvaluateChanNameMes ( const CVector& vecData ) static_cast ( 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 ( GetValFromStream ( vecData, iPos, 1 ) ); @@ -739,15 +739,15 @@ void CProtocol::CreateChatTextMes ( const QString strChatText ) // build data vector CVector vecData ( iEntrLen ); - // number of bytes for name string (2 bytes) + // number of bytes for chat text string (2 bytes) PutValOnStream ( vecData, iPos, static_cast ( 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 ( strChatText[j].toAscii() ), 1 ); + static_cast ( strChatText[i].toAscii() ), 1 ); } CreateAndSendMessage ( PROTMESSID_CHAT_TEXT, vecData ); @@ -763,19 +763,20 @@ bool CProtocol::EvaluateChatTextMes ( const CVector& 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 ( 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 ( GetValFromStream ( vecData, iPos, 1 ) );