| Ticket UUID: | 817f51002f02b6b7edad6898e2c8b1e2167f465 | |||
| Title: | ::rest::simple crashes | |||
| Type: | Bug | Version: | 1.0 | |
| Submitter: | anonymous | Created on: | 2015-09-10 08:18:46 | |
| Subsystem: | rest | Assigned To: | aku | |
| Priority: | 5 Medium | Severity: | Severe | |
| Status: | Closed | Last Modified: | 2015-11-17 02:25:39 | |
| Resolution: | Fixed | Closed By: | aku | |
| Closed on: | 2015-11-17 02:25:39 | |||
| Description: |
::rest::simple uses [info frame] to retrieve its callname - this is not reliable (also see https://groups.google.com/d/msg/comp.lang.tcl/xrtZw8CFcHI/I2A86UC-AAAJ).
#!/usr/bin/env expect
# Demonstrate the odd behaviour of [info frame].
# This breaks ::rest::simple and aliases from tcllib's rest package.
# ::rest::simple tries to get its call name with [namespace tail [lindex [dict get [info frame -1] cmd] 0]], ...
proc simple {args} {
puts stderr ">>>[dict get [info frame -1] cmd]<<<"
lindex [dict get [info frame -1] cmd] 0
}
interp alias {} put {} simple
# 1. the representation depends on control structures, compare these:
put \
A \
B
set do true
while {$do} {
put \
A \
B
set do false
}
# 2. [info frame]'s cmd is not substituted --> simple's approach might not succeed:
set m put
$m A B ;# I cannot think of a workaround.
# 3. [info frame]'s cmd is not a list in general --> simple's approach might crash the app:
put [dict create headers {A B}]
# WORKAROUND:
put [dict create headers {A B} ] ;# take care of "meta-syntax"
| |||
| User Comments: |
aku added on 2015-11-17 02:25:39:
Thank you. Merged, revision [b173bb67cb]. Version bumped to 1.0.2 anonymous (claiming to be heinrichmartin) added on 2015-11-16 08:44:00: Just did a code review. Looks good and the diff is simple (no pun intended) enough to go ahead, merge, and close this ticket; I already tested the previous major changes :-) aku added on 2015-11-10 03:23:56: We have a whitelist in revision [e10a3b6c0fddaec4]. This is on branch [rest-817f51002f]. Please test if that is working for you. Note! This revision also contains a fix for ticket [895baa109a] - Merge config content-type into request headers. aku added on 2015-10-21 12:08:33: A whitelist makes sense. Will implement that. anonymous (claiming to be heinrichmartin) added on 2015-10-21 11:18:22: Works for me: my case is #3 from the description. The rest was only found while debugging ...
Code review for the patch:
- String match \$* is not enough. I'd consider a hard-coded white-list, i.e. if {$cmd ni $::rest::methods} {return -code error}
- remove commented code #puts
HTH
aku added on 2015-10-20 15:40:15: Ok, first attempt at this. Revision [8d718b4d0d]. Branch [rest-817f51002f] Please test if that is working for you. anonymous (claiming to be heinrichmartin) added on 2015-10-20 15:30:35: Well, rest::simple is not doomed; just the aliases ... You could merge the config dict with the correct method and tailcall simple instead. (Error out if simple is called without method. Optionally, put the legacy code in a try-block to be backward-compatible.) aku added on 2015-10-20 15:13:37: Trialed 8.5.8 and 8.4.19. Both resolve the alias causing [info level 0] show the definition name. If it ever was different it was really way back. So, [info level 0] is not usable, contrary to my thoughts. :( So, best bet is to work around the issues with [info frame] as much as possible. That looks to be quite a bit of work. Better do it on a branch. aku added on 2015-10-20 15:04:23: Sigh. Some crow for me to eat. [info level 0] shows the command with aliases resolved. At least for Tcl 8.6.4 I have here. So, use of [info frame] seems to be required. I believe I will test this a bit more, because IIRC some older versions actually showed the alias in [info level 0], not resolved. Back to [info frame] ... The 'cmd' key exposes the processing done by the interpreter on the command, i.e. the while command sees its up-body with the continuation lines resolved, and so the "put ..." is a proper list. With the top-level "put ..." there was no such additional processing before things went to parsing & execution. You see the raw command as found in the sources. IOW if the command is dynamic, through a variable, the 'cmd' key will show something like '$cmd A B', assuming 'set cmd put'. At the moment I do not believe that we can get the name of the command it was invoked with (i.e. aliases) in a sure way. ... rest::simple might be doomed. aku added on 2015-10-20 03:16:27: While [info frame] goes to great lengths to get correct location information, the presence of "eval" makes it impossible to get such under all circumstances. And for the case here, where the location is not even asked for, but just the command (name) itself ?! It should have never been used from the beginning, IMHO. Tcl has [info level] for that. [info level 0] gives the currently running command. [info level -1] the caller. Limitation: [info level -1] may not exist. I.e. when rest::simple is called directly, from the top-level of a script, i.e. level #0. That can be worked around however. | |||
Home
Blog
Docs
Downloads
Tickets
Timeline
Branches
Tags
Wiki