[v2] usertools: replace unsafe input function

Message ID 1554730848-97709-1-git-send-email-andrius.sirvys@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] usertools: replace unsafe input function |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andrius Sirvys April 8, 2019, 1:40 p.m. UTC
  LGTM static code analysis tool reports that the function 'input' is
unsafe. Changed to use raw_input which then converts it using
ast.literal_eval() which is safe.

Fixes: d1b94da4a4e0 ("usertools: add client script for telemetry")
Cc: ciara.power@intel.com

Signed-off-by: Andrius Sirvys <andrius.sirvys@intel.com>
Acked-by: Kevin Laatz <kevin.laatz@intel.com>
---
v2:raw_input doesn't exist in Python 3, added a clause
to check python version
---
 usertools/dpdk-telemetry-client.py | 5 +++++
 1 file changed, 5 insertions(+)
  

Comments

Anatoly Burakov April 9, 2019, 9:10 a.m. UTC | #1
On 08-Apr-19 2:40 PM, Andrius Sirvys wrote:
> LGTM static code analysis tool reports that the function 'input' is
> unsafe. Changed to use raw_input which then converts it using
> ast.literal_eval() which is safe.
> 
> Fixes: d1b94da4a4e0 ("usertools: add client script for telemetry")
> Cc: ciara.power@intel.com
> 
> Signed-off-by: Andrius Sirvys <andrius.sirvys@intel.com>
> Acked-by: Kevin Laatz <kevin.laatz@intel.com>
> ---
> v2:raw_input doesn't exist in Python 3, added a clause
> to check python version
> ---
>   usertools/dpdk-telemetry-client.py | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/usertools/dpdk-telemetry-client.py b/usertools/dpdk-telemetry-client.py
> index ce0c7a9..5f6c47b 100755
> --- a/usertools/dpdk-telemetry-client.py
> +++ b/usertools/dpdk-telemetry-client.py
> @@ -14,6 +14,11 @@
>   API_UNREG = "{\"action\":2,\"command\":\"clients\",\"data\":{\"client_path\":\""
>   DEFAULT_FP = "/var/run/dpdk/default_client"
>   
> +try:
> +	raw_input # Python 2
> +except NameError:
> +	raw_input = input # Python 3
> +
>   class Socket:
>   
>       def __init__(self):
> 

Nitpicking, but PEP8 suggests two spaces before comment rather than one, 
e.g.

code  # comment

rather than

code # comment

Other than that,

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  

Patch

diff --git a/usertools/dpdk-telemetry-client.py b/usertools/dpdk-telemetry-client.py
index ce0c7a9..5f6c47b 100755
--- a/usertools/dpdk-telemetry-client.py
+++ b/usertools/dpdk-telemetry-client.py
@@ -14,6 +14,11 @@ 
 API_UNREG = "{\"action\":2,\"command\":\"clients\",\"data\":{\"client_path\":\""
 DEFAULT_FP = "/var/run/dpdk/default_client"
 
+try:
+	raw_input # Python 2
+except NameError:
+	raw_input = input # Python 3
+
 class Socket:
 
     def __init__(self):