Got a problem thats being doing my head in for the last 2 days.
Im running a tcl script (for an eggdrop) which when triggered, executes a local shell command (child process) and if the command is succesfull it spits out the results. However, if the command is NOT succesful, i get an error "Tcl error [proc_ports]: child process exited abnormally
:.
What i would like is to create a custom response, if the child process did not find any results.
The script is:
set chan "#help"
bind pub -|- .port proc_ports
proc proc_ports {nick host handle channel testes} {
global chan
if {"$chan" == "$channel"} {
return 0
}
if [matchattr $nick |fmn $channel] {
set ports [lindex $testes 0]
set fp [ exec grep -w "$ports" scripts/ports | awk {{$1=""; print $0}} ]
putserv "PRIVMSG $channel :Port \002$ports\002 is normally used for: \002$fp\002"
return 1
} else {
putserv "PRIVMSG $channel :$nick, you do \002NOT\002 have access to this command!"
return 1
}
}
I would love to solve this using TCL, to help me learn more, rather than changing the exec into a shell script that would return any errors.
I have read up on the CATCH command in TCL, and have tried many different approaches to the script, however all have failed me :(
Any help would be appreciated.
Cheers.
You have HUGE security problem.
1a) Variable "testes" contains users TEXT. You considers that "testes" contains valid TCL list and use "lindex" on it. You should use at least command set ports [lindex [split $testes] 0]
1b) Before you send custom text to run in shell you should check to see if it contains illegal characters. Use string is
, regexp
, regsub
.
To check for an error in the execution of commands you can use the following code:
set ports [lindex $testes 0] if { [catch {exec grep -w "$ports" scripts/ports | awk {{$1=""; print $0}}} fp] } { putserv "PRIVMSG $channel :Something wrong while executing command." } { putserv "PRIVMSG $channel :Port \002$ports\002 is normally used for: \002$fp\002" }