diff mbox series

[ovs-dev] odp-util: added NULL check for error pointer argument

Message ID 1552936308-28166-1-git-send-email-cpp.code.lv@gmail.com
State Accepted
Headers show
Series [ovs-dev] odp-util: added NULL check for error pointer argument | expand

Commit Message

Toms Atteka March 18, 2019, 7:11 p.m. UTC
If NULL value was provided for odp_flow_from_string errorp argument
segmentation fault error occurred.

This patch fixes it by ignoring error formatting if error pointer
is not provided.

Reported-at:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12972
Signed-off-by: Toms Atteka <cpp.code.lv@gmail.com>
---
 lib/odp-util.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Comments

Ben Pfaff March 18, 2019, 9:04 p.m. UTC | #1
On Mon, Mar 18, 2019 at 12:11:48PM -0700, Toms Atteka wrote:
> If NULL value was provided for odp_flow_from_string errorp argument
> segmentation fault error occurred.
> 
> This patch fixes it by ignoring error formatting if error pointer
> is not provided.
> 
> Reported-at:
> https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=12972
> Signed-off-by: Toms Atteka <cpp.code.lv@gmail.com>

Thanks, applied to master.

It looks like this does not need backports.
diff mbox series

Patch

diff --git a/lib/odp-util.c b/lib/odp-util.c
index 8bcbd2c..0716161 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -5725,7 +5725,9 @@  odp_flow_from_string(const char *s, const struct simap *port_names,
                      struct ofpbuf *key, struct ofpbuf *mask,
                      char **errorp)
 {
-    *errorp = NULL;
+    if (errorp) {
+        *errorp = NULL;
+    }
 
     const size_t old_size = key->size;
     struct parse_odp_context context = (struct parse_odp_context) {
@@ -5743,7 +5745,9 @@  odp_flow_from_string(const char *s, const struct simap *port_names,
         ovs_u128 ufid;
         retval = odp_ufid_from_string(s, &ufid);
         if (retval < 0) {
-            *errorp = xasprintf("syntax error at %s", s);
+            if (errorp) {
+                *errorp = xasprintf("syntax error at %s", s);
+            }
             key->size = old_size;
             return -retval;
         } else if (retval > 0) {
@@ -5753,7 +5757,9 @@  odp_flow_from_string(const char *s, const struct simap *port_names,
 
         retval = parse_odp_key_mask_attr(&context, s, key, mask);
         if (retval < 0) {
-            *errorp = xasprintf("syntax error at %s", s);
+            if (errorp) {
+                *errorp = xasprintf("syntax error at %s", s);
+            }
             key->size = old_size;
             return -retval;
         }