From: Daniel P. Berrange Date: Thu, 11 May 2017 10:20:59 +0000 (+0100) Subject: rpc: improve error message for bounds check X-Git-Tag: v3.6.0-rc1~233 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8fb3c31594481f54d384eb12fe81b0e6f50dcce;p=thirdparty%2Flibvirt.git rpc: improve error message for bounds check If we exceed a fixed limit in RPC code we get a horrible message like this, if the parameter type is a 'string', because we forgot to initialize the error message type field: $ virsh snapshot-list ostack1 error: too many remote undefineds: 1329 > 1024 It would also be useful to know which RPC call and field was exceeded. So this patch makes us report: $ virsh snapshot-list ostack1 error: too many remote undefineds: 1329 > 1024, in parameter 'names' for 'virDomainSnapshotListNames' Signed-off-by: Daniel P. Berrange --- diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index def88d4f96..e7a48d578a 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -1513,6 +1513,7 @@ elsif ($mode eq "client") { $single_ret_list_name = $1; $single_ret_list_max_var = "max$1"; $single_ret_list_max_define = $2; + $single_ret_list_error_msg_type = "string"; } elsif ($ret_member =~ m/^(admin|remote)_nonnull_string (\S+)<\S+>;/) { # error out on unannotated arrays die "$1_nonnull_string array without insert@ annotation: $ret_member"; @@ -1790,7 +1791,8 @@ elsif ($mode eq "client") { print "\n"; print " if ($single_ret_list_max_var > $single_ret_list_max_define) {\n"; print " virReportError(VIR_ERR_RPC,\n"; - print " _(\"too many remote ${single_ret_list_error_msg_type}s: %d > %d\"),\n"; + print " _(\"too many remote ${single_ret_list_error_msg_type}s: %d > %d,\"\n"; + print " \"in parameter '$single_ret_list_name' for 'vir$call->{ProcName}'\"),\n"; print " $single_ret_list_max_var, $single_ret_list_max_define);\n"; print " goto done;\n"; print " }\n"; @@ -1856,7 +1858,8 @@ elsif ($mode eq "client") { $modern_ret_as_list) { print " if (ret.$single_ret_list_name.${single_ret_list_name}_len > $single_ret_list_max_var) {\n"; print " virReportError(VIR_ERR_RPC,\n"; - print " _(\"too many remote ${single_ret_list_error_msg_type}s: %d > %d\"),\n"; + print " _(\"too many remote ${single_ret_list_error_msg_type}s: %d > %d,\"\n"; + print " \"in parameter '$single_ret_list_name' for 'vir$call->{ProcName}'\"),\n"; print " ret.$single_ret_list_name.${single_ret_list_name}_len, $single_ret_list_max_var);\n"; print " goto cleanup;\n"; print " }\n";