From 6985fce321bfcbb7e1351f2c618f0d14025eb2e5 Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sun, 7 Nov 2010 08:52:27 +0000 Subject: [PATCH] * Fixed a bug that caused 'execute*' commands to fail when trying to run a program without any arguments. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1187 e378c898-3ddf-0310-93e7-cc216c733640 --- src/rpc/command.cc | 8 ++++---- src/rpc/exec_file.cc | 40 +++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/rpc/command.cc b/src/rpc/command.cc index 09940e64..dd3310d7 100644 --- a/src/rpc/command.cc +++ b/src/rpc/command.cc @@ -54,7 +54,7 @@ namespace rpc { template const torrent::Object command_base_call(command_base* rawCommand, target_type target, const torrent::Object& args) { if (!is_target_compatible(target)) - throw torrent::input_error("Target of wrong type."); + throw torrent::input_error("Target of wrong type to command."); return command_base::_call::type, T>(rawCommand, target, args); } @@ -64,7 +64,7 @@ COMMAND_BASE_TEMPLATE_DEFINE(command_base_call); template const torrent::Object command_base_call_value_base(command_base* rawCommand, target_type target, const torrent::Object& rawArgs, int base, int unit) { if (!is_target_compatible(target)) - throw torrent::input_error("Target of wrong type."); + throw torrent::input_error("Target of wrong type to command."); const torrent::Object& arg = convert_to_single_argument(rawArgs); @@ -96,7 +96,7 @@ COMMAND_BASE_TEMPLATE_DEFINE(command_base_call_value_kb); template const torrent::Object command_base_call_string(command_base* rawCommand, target_type target, const torrent::Object& rawArgs) { if (!is_target_compatible(target)) - throw torrent::input_error("Target of wrong type."); + throw torrent::input_error("Target of wrong type to command."); const torrent::Object& arg = convert_to_single_argument(rawArgs); @@ -111,7 +111,7 @@ COMMAND_BASE_TEMPLATE_DEFINE(command_base_call_string); template const torrent::Object command_base_call_list(command_base* rawCommand, target_type target, const torrent::Object& rawArgs) { if (!is_target_compatible(target)) - throw torrent::input_error("Target of wrong type."); + throw torrent::input_error("Target of wrong type to command."); if (rawArgs.type() != torrent::Object::TYPE_LIST) { torrent::Object::list_type arg; diff --git a/src/rpc/exec_file.cc b/src/rpc/exec_file.cc index f1fb9018..8a38b4af 100644 --- a/src/rpc/exec_file.cc +++ b/src/rpc/exec_file.cc @@ -161,25 +161,39 @@ ExecFile::execute_object(const torrent::Object& rawArgs, int flags) { char valueBuffer[buffer_size]; char* valueCurrent = valueBuffer; - const torrent::Object::list_type& args = rawArgs.as_list(); + if (rawArgs.is_list()) { + const torrent::Object::list_type& args = rawArgs.as_list(); - if (args.empty()) - throw torrent::input_error("Too few arguments."); + if (args.empty()) + throw torrent::input_error("Too few arguments."); - for (torrent::Object::list_const_iterator itr = args.begin(), last = args.end(); itr != last; itr++, argsCurrent++) { - if (argsCurrent == argsBuffer + max_args - 1) - throw torrent::input_error("Too many arguments."); + for (torrent::Object::list_const_iterator itr = args.begin(), last = args.end(); itr != last; itr++, argsCurrent++) { + if (argsCurrent == argsBuffer + max_args - 1) + throw torrent::input_error("Too many arguments."); - if (itr->is_string() && (!(flags & flag_expand_tilde) || *itr->as_string().c_str() != '~')) { - *argsCurrent = const_cast(itr->as_string().c_str()); + if (itr->is_string() && (!(flags & flag_expand_tilde) || *itr->as_string().c_str() != '~')) { + *argsCurrent = const_cast(itr->as_string().c_str()); - } else { + } else { + *argsCurrent = valueCurrent; + valueCurrent = print_object(valueCurrent, valueBuffer + buffer_size, &*itr, flags) + 1; + + if (valueCurrent >= valueBuffer + buffer_size) + throw torrent::input_error("Overflowed execute arg buffer."); + } + } + + } else { + const torrent::Object::string_type& args = rawArgs.as_string(); + + if ((flags & flag_expand_tilde) && args.c_str()[0] == '~') { *argsCurrent = valueCurrent; - valueCurrent = print_object(valueCurrent, valueBuffer + buffer_size, &*itr, flags) + 1; + valueCurrent = print_object(valueCurrent, valueBuffer + buffer_size, &rawArgs, flags) + 1; + } else { + *argsCurrent = const_cast(args.c_str()); + } - if (valueCurrent >= valueBuffer + buffer_size) - throw torrent::input_error("Overflowed execute arg buffer."); - } + argsCurrent++; } *argsCurrent = NULL;