Skip to content

Commit

Permalink
msi: Fix handling of single quoted column names in SELECT queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Leidekker authored and julliard committed Dec 23, 2011
1 parent bde25b2 commit ca49aae
Show file tree
Hide file tree
Showing 5 changed files with 331 additions and 20 deletions.
1 change: 1 addition & 0 deletions dlls/msi/msipriv.h
Expand Up @@ -47,6 +47,7 @@ static const BOOL is_64bit = sizeof(void *) > sizeof(int);
#define MSITYPE_NULLABLE 0x1000
#define MSITYPE_KEY 0x2000
#define MSITYPE_TEMPORARY 0x4000
#define MSITYPE_UNKNOWN 0x8000

#define MAX_STREAM_NAME_LEN 62
#define LONG_STR_BYTES 3
Expand Down
2 changes: 2 additions & 0 deletions dlls/msi/msiquery.c
Expand Up @@ -501,6 +501,8 @@ static UINT msi_set_record_type_string( MSIRECORD *rec, UINT field,
szType[0] = 'v';
else if (type & MSITYPE_LOCALIZABLE)
szType[0] = 'l';
else if (type & MSITYPE_UNKNOWN)
szType[0] = 'f';
else if (type & MSITYPE_STRING)
{
if (temporary)
Expand Down
39 changes: 29 additions & 10 deletions dlls/msi/select.c
Expand Up @@ -57,11 +57,15 @@ static UINT SELECT_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT
if( !sv->table )
return ERROR_FUNCTION_FAILED;

if( (col==0) || (col>sv->num_cols) )
if( !col || col > sv->num_cols )
return ERROR_FUNCTION_FAILED;

col = sv->cols[ col - 1 ];

if( !col )
{
*val = 0;
return ERROR_SUCCESS;
}
return sv->table->ops->fetch_int( sv->table, row, col, val );
}

Expand All @@ -74,11 +78,15 @@ static UINT SELECT_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IS
if( !sv->table )
return ERROR_FUNCTION_FAILED;

if( (col==0) || (col>sv->num_cols) )
if( !col || col > sv->num_cols )
return ERROR_FUNCTION_FAILED;

col = sv->cols[ col - 1 ];

if( !col )
{
*stm = NULL;
return ERROR_SUCCESS;
}
return sv->table->ops->fetch_stream( sv->table, row, col, stm );
}

Expand Down Expand Up @@ -218,11 +226,18 @@ static UINT SELECT_get_column_info( struct tagMSIVIEW *view, UINT n, LPCWSTR *na
if( !sv->table )
return ERROR_FUNCTION_FAILED;

if( (n==0) || (n>sv->num_cols) )
if( !n || n > sv->num_cols )
return ERROR_FUNCTION_FAILED;

n = sv->cols[ n - 1 ];

if( !n )
{
if (name) *name = szEmpty;
if (type) *type = MSITYPE_UNKNOWN | MSITYPE_VALID;
if (temporary) *temporary = FALSE;
if (table_name) *table_name = szEmpty;
return ERROR_SUCCESS;
}
return sv->table->ops->get_column_info( sv->table, n, name,
type, temporary, table_name );
}
Expand Down Expand Up @@ -360,7 +375,7 @@ static const MSIVIEWOPS select_ops =
static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPCWSTR name,
LPCWSTR table_name )
{
UINT r, n=0;
UINT r, n;
MSIVIEW *table;

TRACE("%p adding %s.%s\n", sv, debugstr_w( table_name ),
Expand All @@ -380,9 +395,13 @@ static UINT SELECT_AddColumn( MSISELECTVIEW *sv, LPCWSTR name,
if( sv->num_cols >= sv->max_cols )
return ERROR_FUNCTION_FAILED;

r = VIEW_find_column( table, name, table_name, &n );
if( r != ERROR_SUCCESS )
return r;
if ( !name[0] ) n = 0;
else
{
r = VIEW_find_column( table, name, table_name, &n );
if( r != ERROR_SUCCESS )
return r;
}

sv->cols[sv->num_cols] = n;
TRACE("Translating column %s from %d -> %d\n",
Expand Down
59 changes: 49 additions & 10 deletions dlls/msi/sql.y
Expand Up @@ -111,16 +111,15 @@ static struct expr * EXPR_wildcard( void *info );
%nonassoc END_OF_FILE ILLEGAL SPACE UNCLOSED_STRING COMMENT FUNCTION
COLUMN AGG_FUNCTION.

%type <string> table tablelist id
%type <column_list> selcollist column column_and_type column_def table_def
%type <string> table tablelist id string
%type <column_list> selcollist collist selcolumn column column_and_type column_def table_def
%type <column_list> column_assignment update_assign_list constlist
%type <query> query from selectfrom unorderdfrom
%type <query> oneupdate onedelete oneselect onequery onecreate oneinsert onealter onedrop
%type <expr> expr val column_val const_val
%type <column_type> column_type data_type data_type_l data_count
%type <integer> number alterop

/* Reference: http://mates.ms.mff.cuni.cz/oracle/doc/ora815nt/server.815/a67779/operator.htm */
%left TK_OR
%left TK_AND
%left TK_NOT
Expand Down Expand Up @@ -148,7 +147,7 @@ onequery:
;

oneinsert:
TK_INSERT TK_INTO table TK_LP selcollist TK_RP TK_VALUES TK_LP constlist TK_RP
TK_INSERT TK_INTO table TK_LP collist TK_RP TK_VALUES TK_LP constlist TK_RP
{
SQL_input *sql = (SQL_input*) info;
MSIVIEW *insert = NULL;
Expand All @@ -159,7 +158,7 @@ oneinsert:

PARSER_BUBBLE_UP_VIEW( sql, $$, insert );
}
| TK_INSERT TK_INTO table TK_LP selcollist TK_RP TK_VALUES TK_LP constlist TK_RP TK_TEMPORARY
| TK_INSERT TK_INTO table TK_LP collist TK_RP TK_VALUES TK_LP constlist TK_RP TK_TEMPORARY
{
SQL_input *sql = (SQL_input*) info;
MSIVIEW *insert = NULL;
Expand Down Expand Up @@ -307,7 +306,7 @@ onedrop:
;

table_def:
column_def TK_PRIMARY TK_KEY selcollist
column_def TK_PRIMARY TK_KEY collist
{
if( SQL_MarkPrimaryKeys( &$1, $4 ) )
$$ = $1;
Expand Down Expand Up @@ -448,8 +447,20 @@ selectfrom:
;

selcollist:
selcolumn
| selcolumn TK_COMMA selcollist
{
$1->next = $3;
}
| TK_STAR
{
$$ = NULL;
}
;

collist:
column
| column TK_COMMA selcollist
| column TK_COMMA collist
{
$1->next = $3;
}
Expand All @@ -472,7 +483,7 @@ from:

PARSER_BUBBLE_UP_VIEW( sql, $$, table );
}
| unorderdfrom TK_ORDER TK_BY selcollist
| unorderdfrom TK_ORDER TK_BY collist
{
UINT r;

Expand Down Expand Up @@ -520,8 +531,7 @@ tablelist:
{
$$ = $1;
}
|
table TK_COMMA tablelist
| table TK_COMMA tablelist
{
$$ = parser_add_table( info, $3, $1 );
if (!$$)
Expand Down Expand Up @@ -689,6 +699,27 @@ column:
}
;

selcolumn:
table TK_DOT id
{
$$ = parser_alloc_column( info, $1, $3 );
if( !$$ )
YYABORT;
}
| id
{
$$ = parser_alloc_column( info, NULL, $1 );
if( !$$ )
YYABORT;
}
| string
{
$$ = parser_alloc_column( info, NULL, $1 );
if( !$$ )
YYABORT;
}
;

table:
id
{
Expand All @@ -704,6 +735,14 @@ id:
}
;

string:
TK_STRING
{
if ( SQL_getstring( info, &$1, &$$ ) != ERROR_SUCCESS || !$$ )
YYABORT;
}
;

number:
TK_INTEGER
{
Expand Down

0 comments on commit ca49aae

Please sign in to comment.