Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ one_argument
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Greven
Canada (835 posts) 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 | | Top |
|
| Posted by
| David Haley
USA (3,881 posts) 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 | | Top |
|
| Posted by
| Nick Gammon
Australia (23,166 posts) 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 | | Top |
|
| Posted by
| Gregar
(20 posts) 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. | | Top |
|
| Posted by
| Samson
USA (683 posts) 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 | | 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.
16,977 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top