diff options
author | Tad Marshall <tad@10gen.com> | 2013-05-30 04:56:25 -0400 |
---|---|---|
committer | Tad Marshall <tad@10gen.com> | 2013-05-30 04:56:25 -0400 |
commit | 3ad9a467b346a617f318f08479f4d194f50c6bdc (patch) | |
tree | c1ef6fcd46d7d56cf536eaf3e46495f9f78748a1 | |
parent | 15145c5b6a1db46e5246bcb2d63ae6ec3d28b3a5 (diff) | |
download | mongo-3ad9a467b346a617f318f08479f4d194f50c6bdc.tar.gz |
SERVER-8931 Do not display stack trace on invalid cd() and mkdir() commands
Validate user input for the cd() and mkdir() JavaScript functions
and use uassert (UserAssertion) on validation failures. This will
be translated into a JavaScript exception (and so can be caught by
user code) and will not generate a stack trace.
-rw-r--r-- | src/mongo/shell/shell_utils_extended.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/mongo/shell/shell_utils_extended.cpp b/src/mongo/shell/shell_utils_extended.cpp index 1e68882a3bc..6c847cbd850 100644 --- a/src/mongo/shell/shell_utils_extended.cpp +++ b/src/mongo/shell/shell_utils_extended.cpp @@ -25,6 +25,7 @@ #include "mongo/shell/shell_utils_launcher.h" #include "mongo/util/file.h" #include "mongo/util/md5.hpp" +#include "mongo/util/mongoutils/str.h" #include "mongo/util/net/sock.h" #include "mongo/util/text.h" @@ -97,16 +98,27 @@ namespace mongo { /** Set process wide current working directory. */ BSONObj cd(const BSONObj& args, void* data) { + uassert(16830, + "cd requires one argument -- cd(directory)", + args.nFields() == 1); + uassert(16831, + "cd requires a string argument -- cd(directory)", + args.firstElement().type() == String); #if defined(_WIN32) - std::wstring dir = toWideString( args.firstElement().String().c_str() ); - if( SetCurrentDirectory(dir.c_str()) ) + std::wstring dir = toWideString(args.firstElement().String().c_str()); + if (SetCurrentDirectoryW(dir.c_str())) { return BSONObj(); + } #else - string dir = args.firstElement().String(); - if( chdir( dir.c_str() ) == 0 ) + std::string dir = args.firstElement().String(); + if (chdir(dir.c_str()) == 0) { return BSONObj(); + } #endif - return BSON( "" << "change directory failed" ); + uasserted(16832, + mongoutils::str::stream() << "cd command failed: " + << errnoWithDescription()); + return BSONObj(); } BSONObj pwd(const BSONObj&, void* data) { @@ -161,6 +173,12 @@ namespace mongo { } BSONObj mkdir(const BSONObj& args, void* data) { + uassert(16833, + "mkdir requires one argument -- mkdir(directory)", + args.nFields() == 1); + uassert(16834, + "mkdir requires a string argument -- mkdir(directory)", + args.firstElement().type() == String); boost::filesystem::create_directories(args.firstElement().String()); return BSON( "" << true ); } |