Commit 60ad75ea authored by James Hawkins's avatar James Hawkins Committed by Alexandre Julliard

msi: Make sure a constant string's quotes match up.

parent a67d80b4
...@@ -49,7 +49,7 @@ typedef struct tag_SQL_input ...@@ -49,7 +49,7 @@ typedef struct tag_SQL_input
struct list *mem; struct list *mem;
} SQL_input; } SQL_input;
static LPWSTR SQL_getstring( void *info, const struct sql_str *str ); static UINT SQL_getstring( void *info, const struct sql_str *strdata, LPWSTR *str );
static INT SQL_getint( void *info ); static INT SQL_getint( void *info );
static int sql_lex( void *SQL_lval, SQL_input *info ); static int sql_lex( void *SQL_lval, SQL_input *info );
...@@ -677,8 +677,7 @@ table: ...@@ -677,8 +677,7 @@ table:
id: id:
TK_ID TK_ID
{ {
$$ = SQL_getstring( info, &$1 ); if ( SQL_getstring( info, &$1, &$$ ) != ERROR_SUCCESS || !$$ )
if( !$$ )
YYABORT; YYABORT;
} }
; ;
...@@ -757,11 +756,15 @@ static int sql_lex( void *SQL_lval, SQL_input *sql ) ...@@ -757,11 +756,15 @@ static int sql_lex( void *SQL_lval, SQL_input *sql )
return token; return token;
} }
LPWSTR SQL_getstring( void *info, const struct sql_str *strdata ) UINT SQL_getstring( void *info, const struct sql_str *strdata, LPWSTR *str )
{ {
LPCWSTR p = strdata->data; LPCWSTR p = strdata->data;
UINT len = strdata->len; UINT len = strdata->len;
LPWSTR str;
/* match quotes */
if( ( (p[0]=='`') && (p[len-1]!='`') ) ||
( (p[0]=='\'') && (p[len-1]!='\'') ) )
return ERROR_FUNCTION_FAILED;
/* if there's quotes, remove them */ /* if there's quotes, remove them */
if( ( (p[0]=='`') && (p[len-1]=='`') ) || if( ( (p[0]=='`') && (p[len-1]=='`') ) ||
...@@ -770,13 +773,13 @@ LPWSTR SQL_getstring( void *info, const struct sql_str *strdata ) ...@@ -770,13 +773,13 @@ LPWSTR SQL_getstring( void *info, const struct sql_str *strdata )
p++; p++;
len -= 2; len -= 2;
} }
str = parser_alloc( info, (len + 1)*sizeof(WCHAR) ); *str = parser_alloc( info, (len + 1)*sizeof(WCHAR) );
if( !str ) if( !*str )
return str; return ERROR_OUTOFMEMORY;
memcpy( str, p, len*sizeof(WCHAR) ); memcpy( *str, p, len*sizeof(WCHAR) );
str[len]=0; (*str)[len]=0;
return str; return ERROR_SUCCESS;
} }
INT SQL_getint( void *info ) INT SQL_getint( void *info )
...@@ -867,7 +870,11 @@ static struct expr * EXPR_sval( void *info, const struct sql_str *str ) ...@@ -867,7 +870,11 @@ static struct expr * EXPR_sval( void *info, const struct sql_str *str )
if( e ) if( e )
{ {
e->type = EXPR_SVAL; e->type = EXPR_SVAL;
e->u.sval = SQL_getstring( info, str ); if( SQL_getstring( info, str, (LPWSTR *)&e->u.sval ) != ERROR_SUCCESS )
{
msi_free( e );
return NULL;
}
} }
return e; return e;
} }
......
...@@ -651,7 +651,10 @@ static void test_msibadqueries(void) ...@@ -651,7 +651,10 @@ static void test_msibadqueries(void)
ok(r == ERROR_SUCCESS , "query failed\n"); ok(r == ERROR_SUCCESS , "query failed\n");
r = try_query( hdb, "select * from c where b = 'x"); r = try_query( hdb, "select * from c where b = 'x");
todo_wine ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n"); ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
r = try_query( hdb, "select * from c where b = 'x'");
ok(r == ERROR_SUCCESS, "query failed\n");
r = try_query( hdb, "select * from 'c'"); r = try_query( hdb, "select * from 'c'");
ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n"); ok(r == ERROR_BAD_QUERY_SYNTAX, "query failed\n");
......
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