ofp-util: Avoid ovs_fatal() in ofputil_parse_key_value().
authorBen Pfaff <blp@nicira.com>
Fri, 27 Apr 2012 16:41:02 +0000 (09:41 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 7 May 2012 18:23:31 +0000 (11:23 -0700)
ofputil_parse_key_value() is safe to use from a process that must not abort
except in one case: where the argument contains unbalanced parentheses.
This commit eliminates that call to ovs_fatal(), instead just treating the
end of the string as closing all nested parentheses.

It would be better to propagate the error condition upward, but I'm not
sure that it's worth it just for this one corner case.

The purpose of this commit is to make it possible to use this function
indirectly within the "ofproto/trace" implementation, which must never
abort ovs-vswitchd.  (All the current callers are within ovs-ofctl and
other utilities.)

Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/ofp-util.c

index 43776d5..0fadadd 100644 (file)
@@ -3926,7 +3926,8 @@ ofputil_parse_key_value(char **stringp, char **keyp, char **valuep)
         for (value_len = 0; level > 0; value_len++) {
             switch (value[value_len]) {
             case '\0':
         for (value_len = 0; level > 0; value_len++) {
             switch (value[value_len]) {
             case '\0':
-                ovs_fatal(0, "unbalanced parentheses in argument to %s", key);
+                level = 0;
+                break;
 
             case '(':
                 level++;
 
             case '(':
                 level++;