diff mbox series

[ovs-dev] ovs-bugtool: Fix crash when enable --ovs.

Message ID 1604531775-44045-1-git-send-email-u9012063@gmail.com
State Accepted
Headers show
Series [ovs-dev] ovs-bugtool: Fix crash when enable --ovs. | expand

Commit Message

William Tu Nov. 4, 2020, 11:16 p.m. UTC
When enabling '--ovs' or when not using '-y', ovs-bugtool crashes due to
Traceback (most recent call last):
  File "/usr/local/sbin/ovs-bugtool", line 1410, in <module>
    sys.exit(main())
  File "/usr/local/sbin/ovs-bugtool", line 690, in main
    for (k, v) in data.items():
RuntimeError: dictionary changed size during iteration

The patch fixes it by making a copy of the key and value.

VMware-BZ: #2663359
Signed-off-by: William Tu <u9012063@gmail.com>
---
 utilities/bugtool/ovs-bugtool.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Gregory Rose Nov. 4, 2020, 11:54 p.m. UTC | #1
On 11/4/2020 3:16 PM, William Tu wrote:
> When enabling '--ovs' or when not using '-y', ovs-bugtool crashes due to
> Traceback (most recent call last):
>    File "/usr/local/sbin/ovs-bugtool", line 1410, in <module>
>      sys.exit(main())
>    File "/usr/local/sbin/ovs-bugtool", line 690, in main
>      for (k, v) in data.items():
> RuntimeError: dictionary changed size during iteration
> 
> The patch fixes it by making a copy of the key and value.
> 
> VMware-BZ: #2663359
> Signed-off-by: William Tu <u9012063@gmail.com>
> ---
>   utilities/bugtool/ovs-bugtool.in | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/utilities/bugtool/ovs-bugtool.in b/utilities/bugtool/ovs-bugtool.in
> index ddb5bc8dc54c..3792502e7a0c 100755
> --- a/utilities/bugtool/ovs-bugtool.in
> +++ b/utilities/bugtool/ovs-bugtool.in
> @@ -687,7 +687,7 @@ exclude those logs from the archive.
>                            CAP_OPENVSWITCH_LOGS, CAP_NETWORK_CONFIG]
>           ovs_info_list = ['process-tree']
>           # We cannot use iteritems, since we modify 'data' as we pass through
> -        for (k, v) in data.items():
> +        for (k, v) in list(data.items()):
>               cap = v['cap']
>               if 'filename' in v:
>                   info = k[0]
> @@ -708,7 +708,7 @@ exclude those logs from the archive.
>   
>       # permit the user to filter out data
>       # We cannot use iteritems, since we modify 'data' as we pass through
> -    for (k, v) in data.items():
> +    for (k, v) in list(data.items()):
>           cap = v['cap']
>           if 'filename' in v:
>               key = k[0]
> 

I didn't test it but the patch does what you say it does. It
should work to prevent the traceback.

Acked-by: Greg Rose <gvrose8192@gmail.com>
Ilya Maximets Nov. 5, 2020, 4:53 p.m. UTC | #2
On 11/5/20 12:54 AM, Gregory Rose wrote:
> 
> On 11/4/2020 3:16 PM, William Tu wrote:
>> When enabling '--ovs' or when not using '-y', ovs-bugtool crashes due to
>> Traceback (most recent call last):
>>    File "/usr/local/sbin/ovs-bugtool", line 1410, in <module>
>>      sys.exit(main())
>>    File "/usr/local/sbin/ovs-bugtool", line 690, in main
>>      for (k, v) in data.items():
>> RuntimeError: dictionary changed size during iteration
>>
>> The patch fixes it by making a copy of the key and value.
>>
>> VMware-BZ: #2663359
>> Signed-off-by: William Tu <u9012063@gmail.com>
>> ---
>>   utilities/bugtool/ovs-bugtool.in | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/utilities/bugtool/ovs-bugtool.in b/utilities/bugtool/ovs-bugtool.in
>> index ddb5bc8dc54c..3792502e7a0c 100755
>> --- a/utilities/bugtool/ovs-bugtool.in
>> +++ b/utilities/bugtool/ovs-bugtool.in
>> @@ -687,7 +687,7 @@ exclude those logs from the archive.
>>                            CAP_OPENVSWITCH_LOGS, CAP_NETWORK_CONFIG]
>>           ovs_info_list = ['process-tree']
>>           # We cannot use iteritems, since we modify 'data' as we pass through
>> -        for (k, v) in data.items():
>> +        for (k, v) in list(data.items()):
>>               cap = v['cap']
>>               if 'filename' in v:
>>                   info = k[0]
>> @@ -708,7 +708,7 @@ exclude those logs from the archive.
>>         # permit the user to filter out data
>>       # We cannot use iteritems, since we modify 'data' as we pass through
>> -    for (k, v) in data.items():
>> +    for (k, v) in list(data.items()):
>>           cap = v['cap']
>>           if 'filename' in v:
>>               key = k[0]
>>
> 
> I didn't test it but the patch does what you say it does. It
> should work to prevent the traceback.
> 
> Acked-by: Greg Rose <gvrose8192@gmail.com>

Thanks!

I updated the comment a bit and applied to master.  Backported down to 2.13.

Best regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/utilities/bugtool/ovs-bugtool.in b/utilities/bugtool/ovs-bugtool.in
index ddb5bc8dc54c..3792502e7a0c 100755
--- a/utilities/bugtool/ovs-bugtool.in
+++ b/utilities/bugtool/ovs-bugtool.in
@@ -687,7 +687,7 @@  exclude those logs from the archive.
                          CAP_OPENVSWITCH_LOGS, CAP_NETWORK_CONFIG]
         ovs_info_list = ['process-tree']
         # We cannot use iteritems, since we modify 'data' as we pass through
-        for (k, v) in data.items():
+        for (k, v) in list(data.items()):
             cap = v['cap']
             if 'filename' in v:
                 info = k[0]
@@ -708,7 +708,7 @@  exclude those logs from the archive.
 
     # permit the user to filter out data
     # We cannot use iteritems, since we modify 'data' as we pass through
-    for (k, v) in data.items():
+    for (k, v) in list(data.items()):
         cap = v['cap']
         if 'filename' in v:
             key = k[0]