diff mbox series

[ovs-dev] dpctl: fix segfault on ct-{set,del}-limits

Message ID 20240422123742.1324328-1-pvalerio@redhat.com
State Accepted
Delegated to: Simon Horman
Headers show
Series [ovs-dev] dpctl: fix segfault on ct-{set,del}-limits | expand

Checks

Context Check Description
ovsrobot/apply-robot warning apply and check: warning
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Paolo Valerio April 22, 2024, 12:37 p.m. UTC
When no parameters other than the datapath are specified a segfault
occurs.

Fix it by checking the argument access is inside the bounds.

Signed-off-by: Paolo Valerio <pvalerio@redhat.com>
---
 lib/dpctl.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

Comments

Simon Horman April 23, 2024, 10:48 a.m. UTC | #1
On Mon, Apr 22, 2024 at 02:37:41PM +0200, Paolo Valerio wrote:
> When no parameters other than the datapath are specified a segfault
> occurs.
> 
> Fix it by checking the argument access is inside the bounds.
> 
> Signed-off-by: Paolo Valerio <pvalerio@redhat.com>

Acked-by: Simon Horman <horms@ovn.org>
Kevin Traynor April 25, 2024, 10:52 a.m. UTC | #2
On 22/04/2024 13:37, Paolo Valerio wrote:
> When no parameters other than the datapath are specified a segfault
> occurs.
> 
> Fix it by checking the argument access is inside the bounds.
> 
> Signed-off-by: Paolo Valerio <pvalerio@redhat.com>
> ---

Acked-by: Kevin Traynor <ktraynor@redhat.com>

(nit: checkpatch complained about the subject summary format. No need to
send a new version, it could be fixed when on apply.)
Simon Horman April 26, 2024, 8:59 a.m. UTC | #3
On Thu, Apr 25, 2024 at 11:52:55AM +0100, Kevin Traynor wrote:
> On 22/04/2024 13:37, Paolo Valerio wrote:
> > When no parameters other than the datapath are specified a segfault
> > occurs.
> > 
> > Fix it by checking the argument access is inside the bounds.
> > 
> > Signed-off-by: Paolo Valerio <pvalerio@redhat.com>
> > ---
> 
> Acked-by: Kevin Traynor <ktraynor@redhat.com>
> 
> (nit: checkpatch complained about the subject summary format. No need to
> send a new version, it could be fixed when on apply.)

Thanks Kevin,

I will fix this when applying.
Which I plan to do shortly.
Simon Horman April 26, 2024, 9:19 a.m. UTC | #4
On Fri, Apr 26, 2024 at 09:59:50AM +0100, Simon Horman wrote:
> On Thu, Apr 25, 2024 at 11:52:55AM +0100, Kevin Traynor wrote:
> > On 22/04/2024 13:37, Paolo Valerio wrote:
> > > When no parameters other than the datapath are specified a segfault
> > > occurs.
> > > 
> > > Fix it by checking the argument access is inside the bounds.
> > > 
> > > Signed-off-by: Paolo Valerio <pvalerio@redhat.com>
> > > ---
> > 
> > Acked-by: Kevin Traynor <ktraynor@redhat.com>
> > 
> > (nit: checkpatch complained about the subject summary format. No need to
> > send a new version, it could be fixed when on apply.)
> 
> Thanks Kevin,
> 
> I will fix this when applying.
> Which I plan to do shortly.

Thanks again Paolo and Kevin,

I have applied this patch to main:
- dpctl: Fix segfault on ct-{set,del}-limits.
  https://github.com/openvswitch/ovs/commit/8ce5c95f089c
diff mbox series

Patch

diff --git a/lib/dpctl.c b/lib/dpctl.c
index 34ee7d0e2..3c555a559 100644
--- a/lib/dpctl.c
+++ b/lib/dpctl.c
@@ -2168,13 +2168,20 @@  static int
 dpctl_ct_set_limits(int argc, const char *argv[],
                     struct dpctl_params *dpctl_p)
 {
-    struct dpif *dpif;
-    struct ds ds = DS_EMPTY_INITIALIZER;
+    struct ovs_list zone_limits = OVS_LIST_INITIALIZER(&zone_limits);
     int i =  dp_arg_exists(argc, argv) ? 2 : 1;
+    struct ds ds = DS_EMPTY_INITIALIZER;
+    struct dpif *dpif = NULL;
     uint32_t default_limit;
-    struct ovs_list zone_limits = OVS_LIST_INITIALIZER(&zone_limits);
+    int error;
+
+    if (i >= argc) {
+        ds_put_cstr(&ds, "too few arguments");
+        error = EINVAL;
+        goto error;
+    }
 
-    int error = opt_dpif_open(argc, argv, dpctl_p, INT_MAX, &dpif);
+    error = opt_dpif_open(argc, argv, dpctl_p, INT_MAX, &dpif);
     if (error) {
         return error;
     }
@@ -2261,11 +2268,17 @@  static int
 dpctl_ct_del_limits(int argc, const char *argv[],
                     struct dpctl_params *dpctl_p)
 {
-    struct dpif *dpif;
+    struct ovs_list zone_limits = OVS_LIST_INITIALIZER(&zone_limits);
+    int i =  dp_arg_exists(argc, argv) ? 2 : 1;
     struct ds ds = DS_EMPTY_INITIALIZER;
+    struct dpif *dpif = NULL;
     int error;
-    int i =  dp_arg_exists(argc, argv) ? 2 : 1;
-    struct ovs_list zone_limits = OVS_LIST_INITIALIZER(&zone_limits);
+
+    if (i >= argc) {
+        ds_put_cstr(&ds, "too few arguments");
+        error = EINVAL;
+        goto error;
+    }
 
     error = opt_dpif_open(argc, argv, dpctl_p, 4, &dpif);
     if (error) {