Skip to content

Commit

Permalink
fixed #590 cut SphinxQL error message larger 512 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
tomatolog committed Dec 17, 2018
1 parent 6362881 commit 8868b20
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/searchd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11532,6 +11532,8 @@ enum MysqlColumnFlag_e
MYSQL_COL_UNSIGNED_FLAG = 32
};

#define SPH_MYSQL_ERROR_MAX_LENGTH 512

void SendMysqlErrorPacket ( ISphOutputBuffer & tOut, BYTE uPacketID, const char * sStmt,
const char * sError, int iCID, MysqlErrors_e iErr )
{
Expand All @@ -11541,6 +11543,17 @@ void SendMysqlErrorPacket ( ISphOutputBuffer & tOut, BYTE uPacketID, const char
LogSphinxqlError ( sStmt, sError, iCID );

int iErrorLen = strlen(sError)+1; // including the trailing zero

// cut the error message to fix isseue with long message for popular clients
if ( iErrorLen>SPH_MYSQL_ERROR_MAX_LENGTH )
{
iErrorLen = SPH_MYSQL_ERROR_MAX_LENGTH;
char * sErr = const_cast<char *>( sError );
sErr[iErrorLen-3] = '.';
sErr[iErrorLen-2] = '.';
sErr[iErrorLen-1] = '.';
sErr[iErrorLen] = '\0';
}
int iLen = 9 + iErrorLen;
int iError = iErr; // pretend to be mysql syntax error for now

Expand Down Expand Up @@ -18060,7 +18073,7 @@ bool LoopClientMySQL ( BYTE & uPacketID, CSphinxqlSession & tSession, CSphString
default:
// default case, unknown command
sError.SetSprintf ( "unknown command (code=%d)", uMysqlCmd );
SendMysqlErrorPacket ( tOut, uPacketID, NULL, sError.cstr(), tThd.m_iConnID, MYSQL_ERR_UNKNOWN_COM_ERROR );
SendMysqlErrorPacket ( tOut, uPacketID, NULL, sError.cstr(), tThd.m_iConnID, MYSQL_ERR_UNKNOWN_COM_ERROR );
break;
}

Expand Down

0 comments on commit 8868b20

Please sign in to comment.