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

Toms Atteka cpp.code.lv at gmail.com
Mon Mar 18 19:11:48 UTC 2019


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 at gmail.com>
---
 lib/odp-util.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

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;
         }
-- 
2.7.4



More information about the dev mailing list