Skip to content

Commit 646f313

Browse files
committed
Fixed bug where bad UTF strings might crash the client
1 parent df77d80 commit 646f313

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

ProcessPreviousLine.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,9 @@ assemble the full text of the original line.
555555
// check for bad UTF8 in the line - otherwise all triggers will fail
556556
if (m_bUTF_8)
557557
{
558+
int erroroffset;
558559
iBad = _pcre_valid_utf8 ((const unsigned char *) (const char *) strCurrentLine,
559-
strCurrentLine.GetLength ());
560+
strCurrentLine.GetLength (), &erroroffset);
560561
if (iBad > 0)
561562
{
562563
m_iUTF8ErrorCount++;

Utilities.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,9 +2865,9 @@ int UMessageBox (const char * sText, UINT nType, const char * sTitle)
28652865

28662866
// convert message text to Unicode
28672867

2868-
iBad = _pcre_valid_utf8 ((unsigned char *) sText, strlen (sText));
2869-
28702868
// use PCRE to validate the string first - if bad, fall back to standard box
2869+
int erroroffset;
2870+
iBad = _pcre_valid_utf8 ((unsigned char *) sText, strlen (sText), &erroroffset);
28712871
if (iBad > 0)
28722872
return ::AfxMessageBox (sText, nType);
28732873

@@ -2886,7 +2886,7 @@ int UMessageBox (const char * sText, UINT nType, const char * sTitle)
28862886

28872887
// now do title
28882888

2889-
iBad = _pcre_valid_utf8 ((unsigned char *) sTitle, strlen (sTitle));
2889+
iBad = _pcre_valid_utf8 ((unsigned char *) sTitle, strlen (sTitle), &erroroffset);
28902890

28912891
// use PCRE to validate the title next - if bad, use "MUSHclient" title
28922892
if (iBad > 0)

install/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MUSHclient version 4.80
22
=======================
33

4-
Thursday, 20th October 2011
4+
Thursday, 10th December 2011
55

66
Author: Nick Gammon
77
Web support: http://www.gammon.com.au/forum/

miniwindow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ void CMiniWindow::FontList (VARIANT & vaResult)
763763
static long CalculateUTF8length (LPCTSTR Text, size_t length)
764764
{
765765

766-
int iBad = _pcre_valid_utf8 ((unsigned char *) Text, length);
766+
int erroroffset;
767+
int iBad = _pcre_valid_utf8 ((unsigned char *) Text, length, &erroroffset);
767768
if (iBad > 0)
768769
return -1;
769770

scripting/lua_utils.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,12 +1346,13 @@ size_t length;
13461346
// argument is string to be checked
13471347
const char * data = luaL_checklstring (L, 1, &length);
13481348

1349-
int iBad = _pcre_valid_utf8 ((unsigned char *) data, length);
1349+
int erroroffset;
1350+
int iBad = _pcre_valid_utf8 ((unsigned char *) data, length, &erroroffset);
13501351

13511352
if (iBad > 0)
13521353
{
13531354
lua_pushnil (L);
1354-
lua_pushnumber (L, iBad + 1);
1355+
lua_pushnumber (L, erroroffset + 1);
13551356
return 2; /* return nil and the offset */
13561357
}
13571358

@@ -1391,12 +1392,13 @@ static int utf8sub (lua_State *L) {
13911392

13921393
// validate
13931394

1394-
int iBad = _pcre_valid_utf8 ((unsigned char *) s, length);
1395+
int erroroffset;
1396+
int iBad = _pcre_valid_utf8 ((unsigned char *) s, length, &erroroffset);
13951397

13961398
if (iBad > 0)
13971399
{
13981400
lua_pushnil (L);
1399-
lua_pushnumber (L, iBad + 1);
1401+
lua_pushnumber (L, erroroffset + 1);
14001402
return 2; /* return nil and the offset */
14011403
}
14021404

stdafx.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ extern "C"
801801

802802
// stuff we borrow from PCRE
803803

804-
extern "C" int _pcre_valid_utf8(const unsigned char *buf, int length);
804+
extern "C" int _pcre_valid_utf8(const unsigned char *buf, int length, int * erroroffset);
805805
extern "C" int _pcre_ord2utf8(int cvalue, unsigned char *buffer);
806806
extern "C" const unsigned char _pcre_utf8_table4[];
807807

0 commit comments

Comments
 (0)