[ovs-dev] [PATCH] ovsdb-idlc: Initialize nonnull string columns for inserted rows.

Ben Pfaff blp at ovn.org
Wed Dec 21 00:17:31 UTC 2016

When a schema column has type "exactly one string", the corresponding
struct member has type "char *" and the documented and expected behavior
is that the string should always be nonnull.  (The code generator even
adds a comment /* Always nonnull. */ in the struct definition.)  In the
case where a value is not available, the string is supposed to be
initialized to "" instead of to NULL.

However, the IDL code for inserting a new row did not properly initialize
the column to "", instead leaving it NULL.  This could cause null pointer
dereferences in corner cases.

This commit fixes the problem.

Reported-by: Lance Richardson <lrichard at redhat.com>
Reported-at: https://mail.openvswitch.org/pipermail/ovs-dev/2016-December/326500.html
Signed-off-by: Ben Pfaff <blp at ovn.org>
 ovsdb/ovsdb-idlc.in | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/ovsdb/ovsdb-idlc.in b/ovsdb/ovsdb-idlc.in
index f1c7a35..721ab50 100755
--- a/ovsdb/ovsdb-idlc.in
+++ b/ovsdb/ovsdb-idlc.in
@@ -452,6 +452,11 @@ void
         for columnName, column in sorted_columns(table):
             if column.type.is_smap():
                 print "    smap_init(&row->%s);" % columnName
+            elif (column.type.n_min == 1 and
+                  column.type.n_max == 1 and
+                  column.type.key.type == ovs.db.types.StringType and
+                  not column.type.value):
+                print "    row->%s = \"\";" % columnName
         print "}"
         # First, next functions.

More information about the dev mailing list