[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  one_argument
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

one_argument

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Tue 16 Dec 2003 09:53 PM (UTC)
Message
Anyone ever notice this:
char *one_argument( char *argument, char *arg_first )
{
    char cEnd;
    sh_int count;

    count = 0;

    while ( isspace(*argument) )
	argument++;

    cEnd = ' ';
    if ( *argument == '\'' || *argument == '"' )
	cEnd = *argument++;

    while ( *argument != '\0' || ++count >= 255 )
    {
	if ( *argument == cEnd )
	{
	    argument++;
	    break;
	}
	*arg_first = LOWER(*argument);
	arg_first++;
	argument++;
    }
    *arg_first = '\0';

    while ( isspace(*argument) )
	argument++;

    return argument;
}

We jus recently noticed this when in a writing buffer, if your input extends past 80 characters, and you enter all CAPS, then it will lower the entire line, since it runs through it using one_argument. Maybe this was somewhere else, thought I would let people know.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Tue 16 Dec 2003 10:33 PM (UTC)
Message
That's interesting to know, that the one_argument function converts its result to lower case. Probably to have case-insensitive argument checking and the like, although this is a very good example of behavior with unpleasant side effects because it was implemented with redudancy. You'll notice, for example, that almost all argument-checking functions (e.g. mset) compare the argument case-insensitively. So it's redundant to first convert to lower-case, and then check without caring about case; and furthermore, converting it to lower case can have bad effects somewhere else.

I'm also unsure of the following line:
while ( *argument != '\0' || ++count >= 255 )


While the argument is not null or the count is greater than 255... that's a little silly, since the count starts out at 0, and therefore won't be greater than 255... this actually will *break* if your string is greater than 255 in length, because *argument will eventually be null, but since your count is bigger than 255, it'll continue... forever!

It should be:
while ( *argument != '\0' || ++count <= 255 )


This will, however, limit your argument size to 255 characters. That seems to have been their intention, though...

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Fri 19 Dec 2003 06:28 AM (UTC)
Message
I was about to say the same thing about the 255 but Ksilyan beat me to it.

The interesting thing is that a quick scan of where one_argument is used, it is usually passed a char x [MAX_INPUT_LENGTH] as an argument, and MAX_INPUT_LENGTH is 1024. Seems strange to limit it to 255 when you generally allow for 1024.

Except, of course that the test as written does the opposite.

Here could be a good test - go to a SMAUG mud and simply type a command with a 260 character argument. If the MUD goes dead you know they haven't picked that one up.

Hmmm - maybe I shouldn't suggest that? Anyway a quick test reveals it triggers the error message "Line too long". This kicks in for a 254 or more character line, so the likelihood of someone typing in a 260-character argument is pretty low. Seems a bit unnecessary to allow for 1024 character arguments all through the code too.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Gregar   (20 posts)  [Biography] bio
Date Reply #3 on Fri 19 Dec 2003 06:18 PM (UTC)
Message
I believe the intent for this function was to prevent someone from running thru your game screaming in all caps. This prevents the occurance by forcing ALL-CAPS to all lower, effectively silencing the twits intent to disrupt.
[Go to top] top

Posted by Samson   USA  (683 posts)  [Biography] bio
Date Reply #4 on Fri 19 Dec 2003 06:57 PM (UTC)
Message
The case smashing of one_argument has been known all along - just look at the do_password function where they comment about it doing just that and having to basically rewrite it so it won't smash.

As for the crash, my code allows input of up to half of MAX_INPUT_LENGTH, which is currently set to 1024, so I can enter lines of up to 512. I just tried to crash my game by entering a ridiculously long ( about 560 or so ) command to the do_look function, using the first word as a valid target, then again with one that isn't. No crashes. It did as expected. The first time it showed me what I looked at, the second it just told me it wasn't there.

If there's a specific command this can be tested with, then maybe it's a fault with just that one command? Anyway, I long ago made my one_argument keep the case of commands passed to it. It doesn't appear to have triggered anything bad as a result. Not even spamming 15 yr olds :P

SmaugMuds.org: http://www.smaugmuds.org - The Smaug MUDs Community Center

"The past was erased, the erasure was forgotten, the lie became truth." -- George Orwell, 1984
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


3,744 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]