Commit 533833b4 authored by Mike McCormack's avatar Mike McCormack Committed by Alexandre Julliard

msi: Validate database fields before inserting them.

parent 71d8f4eb
......@@ -1302,12 +1302,38 @@ static UINT msi_table_find_row( MSITABLEVIEW *tv, MSIRECORD *rec, UINT *row );
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;
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 tagMSIVIEW *view, MSIRECORD *rec )
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 )
......
......@@ -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);
}
/* try all markers */
MsiCloseHandle(rec);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment