addressed amb1230 - BfReadString() erroring on something that should be perfectly valid

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401756
This commit is contained in:
David Anderson 2007-12-03 03:19:21 +00:00
parent 6533e16019
commit dcb77e0918
3 changed files with 328 additions and 316 deletions

View File

@ -484,6 +484,7 @@ static cell_t smn_BfReadString(IPluginContext *pCtx, const cell_t *params)
HandleError herr;
HandleSecurity sec;
bf_read *pBitBuf;
int numChars = 0;
char *buf;
sec.pOwner = NULL;
@ -496,12 +497,14 @@ static cell_t smn_BfReadString(IPluginContext *pCtx, const cell_t *params)
}
pCtx->LocalToPhysAddr(params[2], (cell_t **)&buf);
if (!pBitBuf->ReadString(buf, params[3], params[4] ? true : false))
pBitBuf->ReadString(buf, params[3], params[4], &numChars);
if (pBitBuf->IsOverflowed())
{
return pCtx->ThrowNativeError("Destination string buffer is too short, try increasing its size");
return -numChars - 1;
}
return 1;
return numChars;
}
static cell_t smn_BfReadEntity(IPluginContext *pCtx, const cell_t *params)

View File

@ -247,8 +247,12 @@ native Float:BfReadFloat(Handle:bf);
* @param buffer Destination string buffer.
* @param maxlength Maximum length of output string buffer.
* @param line If true the buffer will be copied until it reaches a '\n' or a null terminator.
* @noreturn
* @error Invalid or incorrect Handle, destination string buffer was too short.
* @return Number of bytes written to the buffer. If the bitbuffer stream overflowed,
* that is, had no terminator before the end of the stream, then a negative
* number will be returned equal to the number of characters written to the
* buffer minus 1. The buffer will be null terminated regardless of the
* return value.
* @error Invalid or incorrect Handle.
*/
native BfReadString(Handle:bf, String:buffer[], maxlength, bool:line=false);

View File

@ -195,7 +195,12 @@ public Action:UserMsg_VGUIMenu(UserMsg:msg_id, Handle:bf, const players[], playe
}
decl String:type[15];
BfReadString(bf, type, sizeof(type));
/* If we don't get a valid string, bail out. */
if (BfReadString(bf, type, sizeof(type)) < 0)
{
return Plugin_Handled;
}
if (BfReadByte(bf) == 1 && BfReadByte(bf) == 0 && (strcmp(type, "scores", false) == 0))
{