[libvirt] [PATCH] rpc: improve error message for bounds check

Daniel P. Berrange posted 1 patch 6 years, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20170511102502.6356-1-berrange@redhat.com
src/rpc/gendispatch.pl | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
[libvirt] [PATCH] rpc: improve error message for bounds check
Posted by Daniel P. Berrange 6 years, 11 months ago
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 <berrange@redhat.com>
---
 src/rpc/gendispatch.pl | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 173189c..0c5e4ba 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -1501,6 +1501,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@<offset> annotation: $ret_member";
@@ -1773,7 +1774,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";
@@ -1839,7 +1841,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";
-- 
2.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] rpc: improve error message for bounds check
Posted by Michal Privoznik 6 years, 11 months ago
On 05/11/2017 12:25 PM, Daniel P. Berrange wrote:
> 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 <berrange@redhat.com>
> ---
>  src/rpc/gendispatch.pl | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] rpc: improve error message for bounds check
Posted by Kashyap Chamarthy 6 years, 11 months ago
On Thu, May 11, 2017 at 11:25:02AM +0100, Daniel P. Berrange wrote:
> 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 <berrange@redhat.com>
> ---
>  src/rpc/gendispatch.pl | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

Thanks for fixing it.

Reviewed-by: Kashyap Chamarthy <kchamart@redhat.com>

[...]

-- 
/kashyap

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list