[SERVER-8931] Shell's cd() and mkdir() functions should validate user input and not print stack trace Created: 11/Mar/13 Updated: 11/Jul/16 Resolved: 30/May/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | 2.4.0-rc2 |
| Fix Version/s: | 2.5.1 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Norberto Fernando Rocha Leite (Inactive) | Assignee: | Tad Marshall |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
macosx source build |
||
| Backwards Compatibility: | Minor Change |
| Operating System: | ALL |
| Participants: |
| Description |
|
running cd() function on the shell produced the following stack trace:
The mkdir() function has the same problem. These functions should throw a UserAssertion on a failure to validate their input arguments, resulting in a JavaScript exceptiojn that can be trapped by user code. They should not print a stack trace. |
| Comments |
| Comment by auto [ 30/May/13 ] |
|
Author: {u'username': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}Message: Validate user input for the cd() and mkdir() JavaScript functions |
| Comment by Tad Marshall [ 21/May/13 ] |
|
Thinking about this some more, I don't think that cd() should return a value; it should throw a JavaScript exception so that user code can use try/catch to handle the error. This is more consistent with the behavior of other commands. |
| Comment by Tad Marshall [ 11/Mar/13 ] |
|
That's OK with me. This will mimic the Windows behavior. We already have a pwd() command, so cd() will just be another way of doing the same thing. |
| Comment by Norberto Fernando Rocha Leite (Inactive) [ 11/Mar/13 ] |
|
tad IMHO what it should not do is a print a stack trace. People usually associate this with buggy software. Definitely would go for a pwd command. |
| Comment by Tad Marshall [ 11/Mar/13 ] |
|
The basic error message ("field not found, expected type 2") has been around for a while (I tested 2.0.4), but the stack trace is newer than that. The cd command is doing no checking that it has a first argument before it tries to read the first argument as a string (type 2), so it just gets a failure reading the field and reports it to the user. The only question is what should cd() with no argument do? In the Windows command prompt, the command "cd" with no argument just displays the current working directory, the same thing that pwd does in Unix. In Unix (Linux, Mac), it changes to the home directory. Another option is to issue a friendlier error message (e.g. "The cd command takes one argument; cd(directory)" or something like that). What do you think it should do? |