Bug 4576 - EngFunc_TraceTexture crashes the server!
EngFunc_TraceTexture crashes the server!
Status: RESOLVED FIXED
Product: AMX Mod X
Classification: Unclassified
Component: Module: Fakemeta
trunk
PC All
: P3 critical
Assigned To: amxmodx-bugs@alliedmods.net
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-08-18 18:45 PDT by ot_207
Modified: 2014-02-08 23:51 PST (History)
2 users (show)

See Also:


Attachments
Proposed patch (1.52 KB, patch)
2010-12-20 11:16 PST, Reuben Morais
no flags Details | Diff | Splinter Review
Corrected proposed path (538 bytes, patch)
2010-12-21 05:10 PST, Vincent Herbet [:Arkshine]
no flags Details | Diff | Splinter Review

Description ot_207 2010-08-18 18:45:28 PDT
It crashes because when it does not find a texture it return NULL pointer and when using the MF_SetAmxString with NULL pointer it crashes the server.

So basically this:

		cRet = MF_GetAmxAddr(amx,params[2]);
		index = cRet[0];
		CHECK_ENTITY(index);
		cRet = MF_GetAmxAddr(amx,params[3]);
		Vec1[0]=amx_ctof(cRet[0]);
		Vec1[1]=amx_ctof(cRet[1]);
		Vec1[2]=amx_ctof(cRet[2]);
		cRet = MF_GetAmxAddr(amx,params[4]);
		Vec2[0]=amx_ctof(cRet[0]);
		Vec2[1]=amx_ctof(cRet[1]);
		Vec2[2]=amx_ctof(cRet[2]);
		temp = (char*)(*g_engfuncs.pfnTraceTexture)(INDEXENT2(index),Vec1,Vec2);
		cRet = MF_GetAmxAddr(amx,params[6]);
		MF_SetAmxString(amx, params[5], temp, cRet[0]);
		return 1;

Should turn into this:

	int index = params[2];

	CHECK_ENTITY(index);

	cell *cRet;
	float Vec1[3], Vec2[3];

	cRet = MF_GetAmxAddr(amx,params[3]);
	Vec1[0]=amx_ctof(cRet[0]);
	Vec1[1]=amx_ctof(cRet[1]);
	Vec1[2]=amx_ctof(cRet[2]);

	cRet = MF_GetAmxAddr(amx,params[4]);
	Vec2[0]=amx_ctof(cRet[0]);
	Vec2[1]=amx_ctof(cRet[1]);
	Vec2[2]=amx_ctof(cRet[2]);

	char *temp = (char*)(g_engfuncs.pfnTraceTexture)(INDEXENT2(index), Vec1, Vec2);
	
	MF_SetAmxString(amx, params[4], (temp == NULL) ? "NOTEXTURE" : temp, params[5]);
	return (temp != NULL);
Comment 1 Reuben Morais 2010-12-20 11:16:14 PST
Created attachment 2477 [details] [review]
Proposed patch

Builds fine, not tested.
Comment 2 Vincent Herbet [:Arkshine] 2010-12-21 05:10:24 PST
Created attachment 2483 [details] [review]
Corrected proposed path

Previous patch is correct but doesn't follow the current code design and style. 
This patch corrects that.

Compiled and tested successfully in-game.

To test, I've used a small plugin. Aim a wall and you should get "NoTexture" instead of a crash.
Plugin : http://pastebin.com/3wkKbB29
Comment 3 Vincent Herbet [:Arkshine] 2013-02-13 00:29:00 PST
Pushed changeset: http://hg.alliedmods.net/amxmodx-central/rev/a4cb0f471bcf
Changelog:
	Fix crash in EngFunc_TraceTexture (bug 4576, r=dvander).
Comment 4 AM Bugzilla Bot 2014-02-08 23:51:37 PST
Commit pushed to master at https://github.com/alliedmodders/amxmodx

https://github.com/alliedmodders/amxmodx/commit/a3aa08637504f0a4aff7f01a2081f4394d5e8b77
Fix crash in EngFunc_TraceTexture (bug 4576, r=dvander).


Former-commit-id: c439946a3451dbdfafa2f542e08bc7f83d586165

Note You need to log in before you can comment on or make changes to this bug.