Пример #1
0
Файл: cmd.c Проект: Slipyx/r1q2
/*
============
Cmd_ExecTrigger
============
*/
void Cmd_ExecTrigger (char *string)
{
	const cmd_trigger_t *trigger;
	char				*text;

	// execute matching triggers
	for(trigger = cmd_triggers; trigger; trigger = trigger->next)
	{
		text = Cmd_MacroExpandString(trigger->match);

		if (text && wildcardfit (text, string))
		{
			Cbuf_AddText(trigger->command);
			Cbuf_AddText("\n");
		}
	}
}
Пример #2
0
/*
============
Cmd_TokenizeString

Parses the given string into command line tokens.
$Cvars will be expanded unless they are in a quoted token
============
*/
void Cmd_TokenizeString (char *text, qboolean macroExpand)
{
	int		i;
	char	*com_token;

// clear the args from the last string
	for (i=0 ; i<cmd_argc ; i++)
		Z_Free (cmd_argv[i]);
		
	cmd_argc = 0;
	cmd_args[0] = 0;
	
	// macro expand the text
	if (macroExpand)
		text = Cmd_MacroExpandString (text);
	if (!text)
		return;

	while (1)
	{
// skip whitespace up to a /n
		while (*text && *text <= ' ' && *text != '\n')
		{
			text++;
		}
		
		if (*text == '\n')
		{	// a newline seperates commands in the buffer
			text++;
			break;
		}

		if (!*text)
			return;

		// set cmd_args to everything after the first arg
		if (cmd_argc == 1)
		{
			int		l;

			// sku - removed potentional buffer overflow 
			//   vulnerability
			strncpy( cmd_args, text, sizeof( cmd_args ) );

			// strip off any trailing whitespace
			l = strlen(cmd_args) - 1;
			for ( ; l >= 0 ; l--)
				if (cmd_args[l] <= ' ')
					cmd_args[l] = 0;
				else
					break;
		}
			
		com_token = COM_Parse (&text);
		if (!text)
			return;

		if (cmd_argc < MAX_STRING_TOKENS)
		{
			cmd_argv[cmd_argc] = (char *) Z_Malloc (strlen(com_token)+1);
			strcpy (cmd_argv[cmd_argc], com_token);
			cmd_argc++;
		}
	}
	
}
Пример #3
0
/*
 * Parses the given string into command line tokens.
 * $Cvars will be expanded unless they are in a quoted token
 */
void
Cmd_TokenizeString(char *text, qboolean macroExpand)
{
    int i;
    const char *com_token;

    /* clear the args from the last string */
    for (i = 0; i < cmd_argc; i++)
    {
        Z_Free(cmd_argv[i]);
    }

    cmd_argc = 0;
    cmd_args[0] = 0;

    /* macro expand the text */
    if (macroExpand)
    {
        text = Cmd_MacroExpandString(text);
    }

    if (!text)
    {
        return;
    }

    while (1)
    {
        /* skip whitespace up to a /n */
        while (*text && *text <= ' ' && *text != '\n')
        {
            text++;
        }

        if (*text == '\n')
        {
            /* a newline seperates commands in the buffer */
            text++;
            break;
        }

        if (!*text)
        {
            return;
        }

        /* set cmd_args to everything after the first arg */
        if (cmd_argc == 1)
        {
            int l;

            strcpy(cmd_args, text);

            /* strip off any trailing whitespace */
            l = strlen(cmd_args) - 1;

            for ( ; l >= 0; l--)
            {
                if (cmd_args[l] <= ' ')
                {
                    cmd_args[l] = 0;
                }

                else
                {
                    break;
                }
            }
        }

        com_token = COM_Parse(&text);

        if (!text)
        {
            return;
        }

        if (cmd_argc < MAX_STRING_TOKENS)
        {
            cmd_argv[cmd_argc] = Z_Malloc(strlen(com_token) + 1);
            strcpy(cmd_argv[cmd_argc], com_token);
            cmd_argc++;
        }
    }
}
Пример #4
0
Файл: cmd.c Проект: Slipyx/r1q2
/*
============
Cmd_TokenizeString

Parses the given string into command line tokens.
$Cvars will be expanded unless they are in a quoted token

R1CH: Modified this to avoid use of Z_Alloc/Z_Free. Using
dynamic memory functions for maybe 4-5 bytes at a time is
a waste...
============
*/
void Cmd_TokenizeString (char *text, qboolean macroExpand)
{
	int			cmd_pointer;
	int			i;
	const char	*com_token;

// clear the args from the last string
	for (i=0 ; i<cmd_argc ; i++)
		cmd_argv[i] = NULL;
		//Z_Free (cmd_argv[i]);
		
	cmd_argc = 0;
	cmd_args[0] = 0;
	cmd_pointer = 0;

	// macro expand the text
	if (macroExpand && strchr(text, '$'))
		text = Cmd_MacroExpandString (text);

	if (!text)
		return;

	for (;;)
	{
		// skip whitespace up to a /n
		while (*text && (*text == '\t' || *text == ' ')  && *text != '\n')
		{
			text++;
		}
		
		if (*text == '\n')
		{	// a newline seperates commands in the buffer
			text++;
			break;
		}

		if (!*text)
			return;

		// set cmd_args to everything after the first arg
		if (cmd_argc == 1)
		{
			int		l;

			strncpy (cmd_args, text, sizeof(cmd_args)-1);

			// strip off any trailing whitespace
			l = (int)strlen(cmd_args) - 1;
			if (l == MAX_STRING_CHARS - 1) {
				Com_Printf ("Cmd_TokenizeString: overflowed, possible attack detected.\nargv[0] = %s, remote = %s, len = %d\n", LOG_GENERAL|LOG_EXPLOIT,
					cmd_argv[0], NET_AdrToString(&net_from), net_message.cursize);
				return;
			}
			for ( ; l >= 0 ; l--)
				if (cmd_args[l] <= ' ')
					cmd_args[l] = 0;
				else
					break;
		}
			
		com_token = COM_Parse (&text);
		if (!text)
			return;

		if (cmd_argc < MAX_STRING_TOKENS)
		{
			int len;
			//cmd_argv[cmd_argc] = Z_TagMalloc (strlen(com_token)+1, TAGMALLOC_CMDTOKEN);
			//strcpy (cmd_argv[cmd_argc], com_token);
			len = (int)strlen(com_token);
			if (len+1 + cmd_pointer >= MAX_STRING_CHARS*2)
			{
				Com_Printf ("Cmd_TokenizeString: overflow\n", LOG_GENERAL);
				return;
			}
			strcpy (cmd_buffer + cmd_pointer, com_token);
			cmd_argv[cmd_argc] = cmd_buffer + cmd_pointer;
			cmd_argc++;
			cmd_pointer += len+1;
		}
	}
	
}
Пример #5
0
/*
-----------------------------------------------------------------------------
 Function: Cmd_TokenizeString -Parses the given string into command line tokens.
 
 Parameters: text -[in] string to tokenize.
			 macroExpand -[in] Expand macro, true for yes, otherwise false.
 
 Returns: Nothing
 
 Notes: 
	$Cvars will be expanded unless they are in a quoted token
-----------------------------------------------------------------------------
*/
PUBLIC void Cmd_TokenizeString( char *text, _boolean macroExpand )
{
	int		i;
	char	*com_token;

// clear the args from the last string
	for( i = 0 ; i < cmd_argc ; ++i )
	{
		Z_Free( cmd_argv[ i ] );
	}
		
	cmd_argc = 0;
	cmd_args[ 0 ] = 0;
	
	// macro expand the text
	if( macroExpand )
	{
		text = Cmd_MacroExpandString( text );
	}

	if( ! text )
	{
		return;
	}

	while( 1 )
	{
// skip whitespace up to a /n
		while( *text && *text <= ' ' && *text != '\n' )
		{
			text++;
		}
		
		if( *text == '\n' )
		{	// a newline seperates commands in the buffer
			text++;
			break;
		}

		if( ! *text )
		{
			return;
		}

		// set cmd_args to everything after the first arg
		if( cmd_argc == 1 )
		{
			int		l;

			my_strlcpy( cmd_args, text, sizeof( cmd_args ) - 1 );

			// strip off any trailing whitespace
			l = strlen( cmd_args ) - 1;
			for( ; l >= 0 ; --l )
			{
				if (cmd_args[l] <= ' ')
				{
					cmd_args[l] = 0;
				}
				else
				{
					break;
				}
			}
		}
			
		com_token = COM_Parse( &text );
		if( ! text )
		{
			return;
		}

		if( cmd_argc < MAX_STRING_TOKENS )
		{
			cmd_argv[ cmd_argc ] = Z_Malloc( strlen( com_token ) + 1 );
			my_strlcpy( cmd_argv[ cmd_argc ], com_token, strlen( com_token ) + 1 );
			cmd_argc++;
		}
	}
	
}