egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

list element followed by "XYZ" instead of space

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Tcl FAQ
View previous topic :: View next topic  
Author Message
stdragon
Owner


Joined: 23 Sep 2001
Posts: 959

PostPosted: Sun Sep 15, 2002 5:33 pm    Post subject: list element followed by "XYZ" instead of space Reply with quote

This common error is caused by improper use of list operations on strings. The most common list operations used in this manner are lindex and lrange. Many scripts will use these commands to extract words from a string. For instance:

Code:

bind pub o|o !kick pub_kick

proc pub_kick {nick uhost hand chan arg} {
  # Person to kick is first arg
  set target [lindex $arg 0]

  # Kick message is remaining words
  set kickmsg [lrange $arg 1 end]

  ...
}


However, if you try to kick someone with a strange nick like {hello}kitty, you will soon encounter an error: list element in braces followed by "kitty" instead of space

So, how do you solve this problem? A lot of scripts use an ugly hack (regsub) to add slashes into the string. That is the wrong way. Tcl provides a command called split that splits a string into a proper list. Each word in the string becomes an element in the list.

Therefore the quick fix for this error is to replace $arg with [split $arg] whenever lindex or lrange is used.

For instance, the above script can be fixed like this:

Code:

bind pub o|o !kick pub_kick

proc pub_kick {nick uhost hand chan arg} {
  # Person to kick is first arg
  set target [lindex [split $arg] 0]

  # Kick message is remaining words
  set kickmsg [lrange [split $arg] 1 end]

  ...
}


Now it will work properly with any nick.

If you need more explanation, please post questions below. Not currently possible
Back to top
View user's profile Send private message Visit poster's website
CoolCold
Voice


Joined: 27 Feb 2003
Posts: 9
Location: Moscow,RU

PostPosted: Mon Mar 03, 2003 9:37 pm    Post subject: using {} [] etc Reply with quote

I think that arguments substitution is one of TCL's features and the same time one of biggest security holes - using {} or [] inproperly,programmer lets intruder to make script work the other way it should...so this short example by stdagon is very impotant I think.
Back to top
View user's profile Send private message
tezoost
Voice


Joined: 11 Feb 2015
Posts: 1

PostPosted: Wed Feb 11, 2015 6:05 am    Post subject: Reply with quote

This will show a multi line traceback to the last error. If you read this you will know what you have to do to prevent this error.
The ugly point is, errorInfo shows always the last error. So, if you use catch and a error has been caused it will show that error last, so be fast Wink.




_____________________________________________
Usman
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Tcl FAQ All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber