Mike McCormack : msi: Validate database fields before inserting them.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Sep 7 05:07:09 CDT 2006


Module: wine
Branch: master
Commit: 533833b4e154782d1d05ac9c1bdc17e0af4be4d4
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=533833b4e154782d1d05ac9c1bdc17e0af4be4d4

Author: Mike McCormack <mike at codeweavers.com>
Date:   Thu Aug 31 17:06:20 2006 +0900

msi: Validate database fields before inserting them.

---

 dlls/msi/table.c    |   39 +++++++++++++++++++++++++++++++++++----
 dlls/msi/tests/db.c |    5 +----
 2 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/dlls/msi/table.c b/dlls/msi/table.c
index fb468bc..51986d7 100644
--- a/dlls/msi/table.c
+++ b/dlls/msi/table.c
@@ -1302,12 +1302,38 @@ static UINT msi_table_find_row( MSITABLE
 
 static UINT table_validate_new( MSITABLEVIEW *tv, MSIRECORD *rec )
 {
-    UINT r, row;
+    UINT r, row, i;
 
+    /* check there's no null values where they're not allowed */
+    for( i = 0; i < tv->num_cols; i++ )
+    {
+        if ( tv->columns[i].type & MSITYPE_NULLABLE )
+            continue;
+
+        if ( tv->columns[i].type & MSITYPE_STRING )
+        {
+            LPCWSTR str;
+
+            str = MSI_RecordGetString( rec, i+1 );
+            if (str == NULL || str[0] == 0)
+                return ERROR_INVALID_DATA;
+        }
+        else
+        {
+            UINT n;
+
+            n = MSI_RecordGetInteger( rec, i+1 );
+            if (n == MSI_NULL_INTEGER)
+                return ERROR_INVALID_DATA;
+        }
+    }
+
+    /* check there's no duplicate keys */
     r = msi_table_find_row( tv, rec, &row );
-    if (r != ERROR_SUCCESS)
-        return ERROR_SUCCESS;
-    return ERROR_INVALID_DATA;
+    if (r == ERROR_SUCCESS)
+        return ERROR_INVALID_DATA;
+
+    return ERROR_SUCCESS;
 }
 
 static UINT msi_table_modify_row( MSITABLEVIEW *tv, MSIRECORD *rec,
@@ -1352,6 +1378,11 @@ static UINT TABLE_insert_row( struct tag
 
     TRACE("%p %p\n", tv, rec );
 
+    /* check that the key is unique - can we find a matching row? */
+    r = table_validate_new( tv, rec );
+    if( r != ERROR_SUCCESS )
+        return ERROR_FUNCTION_FAILED;
+
     r = table_create_new_row( view, &row );
     TRACE("insert_row returned %08x\n", r);
     if( r != ERROR_SUCCESS )
diff --git a/dlls/msi/tests/db.c b/dlls/msi/tests/db.c
index c8d42f9..a35b685 100644
--- a/dlls/msi/tests/db.c
+++ b/dlls/msi/tests/db.c
@@ -1323,10 +1323,7 @@ static void test_markers(void)
     MsiRecordSetString(rec, 3, "haha");
     query = "INSERT INTO `?` ( `One`, `Two` ) VALUES ( ?, '?' )";
     r = run_query(hdb, rec, query);
-    todo_wine
-    {
-        ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
-    }
+    ok(r == ERROR_FUNCTION_FAILED, "Expected ERROR_FUNCTION_FAILED, got %d\n", r);
 
     /* try all markers */
     MsiCloseHandle(rec);




More information about the wine-cvs mailing list