[mw-devel] MW3 r961 - trunk/src
psycodom at sucs.org
psycodom at sucs.org
Thu May 3 18:31:53 BST 2007
Author: psycodom
Date: 2007-05-03 18:31:52 +0100 (Thu, 03 May 2007)
New Revision: 961
Modified:
trunk/src/bork.c
trunk/src/main.c
trunk/src/script.c
trunk/src/script_inst.c
Log:
Fixes #20 by making mw-script supply a MAXTEXTLENGTH buffer to apply_gag
Fixes a buffer overflow and iloop in bork.c
Makes display_message handle exntended chars sensibly.
Modified: trunk/src/bork.c
===================================================================
--- trunk/src/bork.c 2007-05-01 16:37:27 UTC (rev 960)
+++ trunk/src/bork.c 2007-05-03 17:31:52 UTC (rev 961)
@@ -27,7 +27,7 @@
printf("This ruleset contains %d rules.\n",rule);
#endif
- while (tp<len)
+ while (tp<len && bp<MAXTEXTLENGTH-2)
{
if (text[tp]==033)
{
@@ -115,6 +115,7 @@
#ifdef DEBUG
printf("Too Long\n");
#endif
+ tp=len;
break;
}
Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c 2007-05-01 16:37:27 UTC (rev 960)
+++ trunk/src/main.c 2007-05-03 17:31:52 UTC (rev 961)
@@ -1254,6 +1254,7 @@
{
if( ((unsigned char)text[ptr] & 192) == 192 )
{
+ ptr++;
str[0]='-';
while( ((unsigned char)text[ptr] & 192) == 128 && len-ptr > 0)
{
@@ -1270,6 +1271,7 @@
{
if(((unsigned char)text[ptr] & 192)==192 )
{
+ ptr++;
str[1]='-';
while( ((unsigned char)text[ptr] & 192) == 128 && len-ptr > 0)
{
Modified: trunk/src/script.c
===================================================================
--- trunk/src/script.c 2007-05-01 16:37:27 UTC (rev 960)
+++ trunk/src/script.c 2007-05-03 17:31:52 UTC (rev 961)
@@ -656,17 +656,17 @@
var_list_t args;
int num;
int i;
- char *fish;
+ char *function_name;
if ((num=ParseLine(line, bits))<1) return;
- if ((fish = FindLinks(bind_list, bits[0])) == NULL) {
+ if ((function_name = FindLinks(bind_list, bits[0])) == NULL) {
printf("Script bind '%s' not found.\n", bits[0]);
return;
}
- if (is_js(fish)) {
- js_exec(fish, num, bits);
+ if (is_js(function_name)) {
+ js_exec(function_name, num, bits);
return;
}
runaway=0;
@@ -748,27 +748,27 @@
{
struct function *script;
struct code *pc;
- char *fish=NULL;
+ char *function_name=NULL;
int old_rights;
/* publically named scripts */
if (bound)
{
- if ((fish = FindLinks(bind_list, name)) == NULL)
+ if ((function_name = FindLinks(bind_list, name)) == NULL)
{
return(2);
}
}
/* otherwise use the name were given */
- if (fish==NULL) fish=strdup(name);
+ if (function_name==NULL) function_name=strdup(name);
/* look for a defined function by that name */
script=function_list;
- while (script!=NULL && strcasecmp(fish, script->name)) script=script->next;
+ while (script!=NULL && strcasecmp(function_name, script->name)) script=script->next;
if (script==NULL)
{
/* okay, so its not a mwscript function */
- free(fish);
+ free(function_name);
return(1);
}
@@ -822,7 +822,7 @@
Pop_Comparisons(&compare_count, &compare_match);
if (script_terminate==1) script_terminate=0;
- free(fish);
+ free(function_name);
local_vars = NULL;
/* restore old rights */
Modified: trunk/src/script_inst.c
===================================================================
--- trunk/src/script_inst.c 2007-05-01 16:37:27 UTC (rev 960)
+++ trunk/src/script_inst.c 2007-05-03 17:31:52 UTC (rev 961)
@@ -22,6 +22,7 @@
#include "strings.h"
#include "expand.h"
#include "ipc.h"
+#include "iconv.h"
extern struct person *user;
extern long userposn;
@@ -238,7 +239,9 @@
{
int i, size, count;
char *tmp, *p;
-
+ char utf8buff[MAXTEXTLENGTH];
+ int conversion_result;
+
if (pc->argc==0) return;
if (!cm_flags(user->chatmode, CM_ONCHAT, CM_MODE_ANY)) return;
@@ -279,24 +282,44 @@
return;
}
+ conversion_result=convert_string_charset(tmp, "UTF-8", strlen(tmp), utf8buff, "UTF-8", MAXTEXTLENGTH-100, NULL, NULL, NULL, NULL, "%");
+ if(conversion_result < 0)
+ {
+ printf("Error %d occured trying to clean up the script output.\n", conversion_result);
+ free(tmp);
+ return;
+ }
+ if(conversion_result & WINVALIDCHARS)
+ {
+ printf("Error: Your script produced invalid utf-8 which has not been sent.\n");
+ free(tmp);
+ return;
+ }
+ if(conversion_result & WOUTPUTTOOSHORT)
+ {
+ printf("Warning: Your script produced too much text which has been truncated.\n");
+ }
+
+
+
if (!strcasecmp(pc->inst->name, "say"))
{
- chat_say(tmp);
+ chat_say(utf8buff);
}
else if (!strcasecmp(pc->inst->name, "shout"))
{
- apply_gag(tmp);
- talk_send(tmp, 1, user->room);
+ apply_gag(utf8buff);
+ talk_send(utf8buff, 1, user->room);
}
else if (!strcasecmp(pc->inst->name, "emote"))
{
- apply_gag(tmp);
- talk_send(tmp, 2, user->room);
+ apply_gag(utf8buff);
+ talk_send(utf8buff, 2, user->room);
}
else if (!strcasecmp(pc->inst->name, "raw"))
{
- apply_gag(tmp);
- talk_send(tmp, 2, user->room);
+ apply_gag(utf8buff);
+ talk_send(utf8buff, 2, user->room);
}
free(tmp);
}
More information about the mw-devel
mailing list