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; HandleError herr;
HandleSecurity sec; HandleSecurity sec;
bf_read *pBitBuf; bf_read *pBitBuf;
int numChars = 0;
char *buf; char *buf;
sec.pOwner = NULL; 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); 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) static cell_t smn_BfReadEntity(IPluginContext *pCtx, const cell_t *params)

View File

@ -1,312 +1,316 @@
/** /**
* vim: set ts=4 : * vim: set ts=4 :
* ============================================================================= * =============================================================================
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
* ============================================================================= * =============================================================================
* *
* This file is part of the SourceMod/SourcePawn SDK. * This file is part of the SourceMod/SourcePawn SDK.
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the * the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation. * Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
* *
* As a special exception, AlliedModders LLC gives you permission to link the * As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the * code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in * by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants * all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further * this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>. * or <http://www.sourcemod.net/license.php>.
* *
* Version: $Id$ * Version: $Id$
*/ */
#if defined _bitbuffer_included #if defined _bitbuffer_included
#endinput #endinput
#endif #endif
#define _bitbuffer_included #define _bitbuffer_included
/** /**
* Writes a single bit to a writable bitbuffer (bf_write). * Writes a single bit to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param bit Bit to write (true for 1, false for 0). * @param bit Bit to write (true for 1, false for 0).
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteBool(Handle:bf, bool:bit); native BfWriteBool(Handle:bf, bool:bit);
/** /**
* Writes a byte to a writable bitbuffer (bf_write). * Writes a byte to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param byte Byte to write (value will be written as 8bit). * @param byte Byte to write (value will be written as 8bit).
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteByte(Handle:bf, byte); native BfWriteByte(Handle:bf, byte);
/** /**
* Writes a byte to a writable bitbuffer (bf_write). * Writes a byte to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param chr Character to write. * @param chr Character to write.
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteChar(Handle:bf, chr); native BfWriteChar(Handle:bf, chr);
/** /**
* Writes a 16bit integer to a writable bitbuffer (bf_write). * Writes a 16bit integer to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param num Integer to write (value will be written as 16bit). * @param num Integer to write (value will be written as 16bit).
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteShort(Handle:bf, num); native BfWriteShort(Handle:bf, num);
/** /**
* Writes a 16bit unsigned integer to a writable bitbuffer (bf_write). * Writes a 16bit unsigned integer to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param num Integer to write (value will be written as 16bit). * @param num Integer to write (value will be written as 16bit).
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteWord(Handle:bf, num); native BfWriteWord(Handle:bf, num);
/** /**
* Writes a normal integer to a writable bitbuffer (bf_write). * Writes a normal integer to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param num Integer to write (value will be written as 32bit). * @param num Integer to write (value will be written as 32bit).
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteNum(Handle:bf, num); native BfWriteNum(Handle:bf, num);
/** /**
* Writes a floating point number to a writable bitbuffer (bf_write). * Writes a floating point number to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param num Number to write. * @param num Number to write.
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteFloat(Handle:bf, Float:num); native BfWriteFloat(Handle:bf, Float:num);
/** /**
* Writes a string to a writable bitbuffer (bf_write). * Writes a string to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param string Text string to write. * @param string Text string to write.
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteString(Handle:bf, const String:string[]); native BfWriteString(Handle:bf, const String:string[]);
/** /**
* Writes an entity to a writable bitbuffer (bf_write). * Writes an entity to a writable bitbuffer (bf_write).
* @note This is a wrapper around BfWriteShort(). * @note This is a wrapper around BfWriteShort().
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param ent Entity index to write. * @param ent Entity index to write.
* @noreturn * @noreturn
* @error Invalid or incorrect Handle, or invalid entity. * @error Invalid or incorrect Handle, or invalid entity.
*/ */
native BfWriteEntity(Handle:bf, ent); native BfWriteEntity(Handle:bf, ent);
/** /**
* Writes a bit angle to a writable bitbuffer (bf_write). * Writes a bit angle to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param angle Angle to write. * @param angle Angle to write.
* @param numBits Optional number of bits to use. * @param numBits Optional number of bits to use.
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteAngle(Handle:bf, Float:angle, numBits=8); native BfWriteAngle(Handle:bf, Float:angle, numBits=8);
/** /**
* Writes a coordinate to a writable bitbuffer (bf_write). * Writes a coordinate to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param coord Coordinate to write. * @param coord Coordinate to write.
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteCoord(Handle:bf, Float:coord); native BfWriteCoord(Handle:bf, Float:coord);
/** /**
* Writes a 3D vector of coordinates to a writable bitbuffer (bf_write). * Writes a 3D vector of coordinates to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param coord Coordinate array to write. * @param coord Coordinate array to write.
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteVecCoord(Handle:bf, Float:coord[3]); native BfWriteVecCoord(Handle:bf, Float:coord[3]);
/** /**
* Writes a 3D normal vector to a writable bitbuffer (bf_write). * Writes a 3D normal vector to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param vec Vector to write. * @param vec Vector to write.
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteVecNormal(Handle:bf, Float:vec[3]); native BfWriteVecNormal(Handle:bf, Float:vec[3]);
/** /**
* Writes a 3D angle vector to a writable bitbuffer (bf_write). * Writes a 3D angle vector to a writable bitbuffer (bf_write).
* *
* @param bf bf_write handle to write to. * @param bf bf_write handle to write to.
* @param angles Angle vector to write. * @param angles Angle vector to write.
* @noreturn * @noreturn
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfWriteAngles(Handle:bf, Float:angles[3]); native BfWriteAngles(Handle:bf, Float:angles[3]);
/** /**
* Reads a single bit from a readable bitbuffer (bf_read). * Reads a single bit from a readable bitbuffer (bf_read).
* *
* @param bf bf_read handle to read from. * @param bf bf_read handle to read from.
* @return Bit value read. * @return Bit value read.
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native bool:BfReadBool(Handle:bf); native bool:BfReadBool(Handle:bf);
/** /**
* Reads a byte from a readable bitbuffer (bf_read). * Reads a byte from a readable bitbuffer (bf_read).
* *
* @param bf bf_read handle to read from. * @param bf bf_read handle to read from.
* @return Byte value read (read as 8bit). * @return Byte value read (read as 8bit).
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfReadByte(Handle:bf); native BfReadByte(Handle:bf);
/** /**
* Reads a character from a readable bitbuffer (bf_read). * Reads a character from a readable bitbuffer (bf_read).
* *
* @param bf bf_read handle to read from. * @param bf bf_read handle to read from.
* @return Character value read. * @return Character value read.
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfReadChar(Handle:bf); native BfReadChar(Handle:bf);
/** /**
* Reads a 16bit integer from a readable bitbuffer (bf_read). * Reads a 16bit integer from a readable bitbuffer (bf_read).
* *
* @param bf bf_read handle to read from. * @param bf bf_read handle to read from.
* @return Integer value read (read as 16bit). * @return Integer value read (read as 16bit).
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfReadShort(Handle:bf); native BfReadShort(Handle:bf);
/** /**
* Reads a 16bit unsigned integer from a readable bitbuffer (bf_read). * Reads a 16bit unsigned integer from a readable bitbuffer (bf_read).
* *
* @param bf bf_read handle to read from. * @param bf bf_read handle to read from.
* @return Integer value read (read as 16bit). * @return Integer value read (read as 16bit).
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfReadWord(Handle:bf); native BfReadWord(Handle:bf);
/** /**
* Reads a normal integer to a readable bitbuffer (bf_read). * Reads a normal integer to a readable bitbuffer (bf_read).
* *
* @param bf bf_read handle to read from. * @param bf bf_read handle to read from.
* @return Integer value read (read as 32bit). * @return Integer value read (read as 32bit).
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native BfReadNum(Handle:bf); native BfReadNum(Handle:bf);
/** /**
* Reads a floating point number from a readable bitbuffer (bf_read). * Reads a floating point number from a readable bitbuffer (bf_read).
* *
* @param bf bf_read handle to read from. * @param bf bf_read handle to read from.
* @return Floating point value read. * @return Floating point value read.
* @error Invalid or incorrect Handle. * @error Invalid or incorrect Handle.
*/ */
native Float:BfReadFloat(Handle:bf); native Float:BfReadFloat(Handle:bf);
/** /**
* Reads a string from a readable bitbuffer (bf_read). * Reads a string from a readable bitbuffer (bf_read).
* *
* @param bf bf_read handle to read from. * @param bf bf_read handle to read from.
* @param buffer Destination string buffer. * @param buffer Destination string buffer.
* @param maxlength Maximum length of output 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. * @param line If true the buffer will be copied until it reaches a '\n' or a null terminator.
* @noreturn * @return Number of bytes written to the buffer. If the bitbuffer stream overflowed,
* @error Invalid or incorrect Handle, destination string buffer was too short. * 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
native BfReadString(Handle:bf, String:buffer[], maxlength, bool:line=false); * buffer minus 1. The buffer will be null terminated regardless of the
* return value.
/** * @error Invalid or incorrect Handle.
* Reads an entity from a readable bitbuffer (bf_read). */
* @note This is a wrapper around BfReadShort(). native BfReadString(Handle:bf, String:buffer[], maxlength, bool:line=false);
*
* @param bf bf_read handle to read from. /**
* @return Entity index read. * Reads an entity from a readable bitbuffer (bf_read).
* @error Invalid or incorrect Handle. * @note This is a wrapper around BfReadShort().
*/ *
native BfReadEntity(Handle:bf); * @param bf bf_read handle to read from.
* @return Entity index read.
/** * @error Invalid or incorrect Handle.
* Reads a bit angle from a readable bitbuffer (bf_read). */
* native BfReadEntity(Handle:bf);
* @param bf bf_read handle to read from.
* @param numBits Optional number of bits to use. /**
* @return Angle read. * Reads a bit angle from a readable bitbuffer (bf_read).
* @error Invalid or incorrect Handle. *
*/ * @param bf bf_read handle to read from.
native Float:BfReadAngle(Handle:bf, numBits=8); * @param numBits Optional number of bits to use.
* @return Angle read.
/** * @error Invalid or incorrect Handle.
* Reads a coordinate from a readable bitbuffer (bf_read). */
* native Float:BfReadAngle(Handle:bf, numBits=8);
* @param bf bf_read handle to read from.
* @return Coordinate read. /**
* @error Invalid or incorrect Handle. * Reads a coordinate from a readable bitbuffer (bf_read).
*/ *
native Float:BfReadCoord(Handle:bf); * @param bf bf_read handle to read from.
* @return Coordinate read.
/** * @error Invalid or incorrect Handle.
* Reads a 3D vector of coordinates from a readable bitbuffer (bf_read). */
* native Float:BfReadCoord(Handle:bf);
* @param bf bf_read handle to read from.
* @param coord Destination coordinate array. /**
* @noreturn * Reads a 3D vector of coordinates from a readable bitbuffer (bf_read).
* @error Invalid or incorrect Handle. *
*/ * @param bf bf_read handle to read from.
native BfReadVecCoord(Handle:bf, Float:coord[3]); * @param coord Destination coordinate array.
* @noreturn
/** * @error Invalid or incorrect Handle.
* Reads a 3D normal vector from a readable bitbuffer (bf_read). */
* native BfReadVecCoord(Handle:bf, Float:coord[3]);
* @param bf bf_read handle to read from.
* @param vec Destination vector array. /**
* @noreturn * Reads a 3D normal vector from a readable bitbuffer (bf_read).
* @error Invalid or incorrect Handle. *
*/ * @param bf bf_read handle to read from.
native BfReadVecNormal(Handle:bf, Float:vec[3]); * @param vec Destination vector array.
* @noreturn
/** * @error Invalid or incorrect Handle.
* Reads a 3D angle vector from a readable bitbuffer (bf_read). */
* native BfReadVecNormal(Handle:bf, Float:vec[3]);
* @param bf bf_read handle to read from.
* @param angles Destination angle vector. /**
* @noreturn * Reads a 3D angle vector from a readable bitbuffer (bf_read).
* @error Invalid or incorrect Handle. *
*/ * @param bf bf_read handle to read from.
native BfReadAngles(Handle:bf, Float:angles[3]); * @param angles Destination angle vector.
* @noreturn
* @error Invalid or incorrect Handle.
*/
native BfReadAngles(Handle:bf, Float:angles[3]);

View File

@ -195,7 +195,12 @@ public Action:UserMsg_VGUIMenu(UserMsg:msg_id, Handle:bf, const players[], playe
} }
decl String:type[15]; 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)) if (BfReadByte(bf) == 1 && BfReadByte(bf) == 0 && (strcmp(type, "scores", false) == 0))
{ {