Commit e8aa851f authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

setupapi: Fix parsing of inf files containing garbage at the beginning of the file.

parent ed54b881
......@@ -114,6 +114,7 @@ struct parser
int cur_section; /* index of section being parsed*/
struct line *line; /* current line */
unsigned int line_pos; /* current line position in file */
unsigned int broken_line; /* first line containing invalid data (if any) */
unsigned int error; /* error code */
unsigned int token_len; /* current token len */
WCHAR token[MAX_FIELD_LEN+1]; /* current token */
......@@ -600,12 +601,15 @@ static const WCHAR *line_start_state( struct parser *parser, const WCHAR *pos )
set_state( parser, SECTION_NAME );
return p + 1;
default:
if (!isspaceW(*p))
if (isspaceW(*p)) break;
if (parser->cur_section != -1)
{
parser->start = p;
set_state( parser, KEY_NAME );
return p;
}
if (!parser->broken_line)
parser->broken_line = parser->line_pos;
break;
}
}
......@@ -886,6 +890,7 @@ static DWORD parse_buffer( struct inf_file *file, const WCHAR *buffer, const WCH
parser.stack_pos = 0;
parser.cur_section = -1;
parser.line_pos = 1;
parser.broken_line = 0;
parser.error = 0;
parser.token_len = 0;
......@@ -916,6 +921,13 @@ static DWORD parse_buffer( struct inf_file *file, const WCHAR *buffer, const WCH
/* find the [strings] section */
file->strings_section = find_section( file, Strings );
if (file->strings_section == -1 && parser.broken_line)
{
if (error_line) *error_line = parser.broken_line;
return ERROR_EXPECTED_SECTION_NAME;
}
return 0;
}
......
......@@ -133,6 +133,18 @@ static const struct
{ STD_HEADER " [Test\x00Section]\n", ERROR_BAD_SECTION_NAME_LINE, 3, FALSE },
{ STD_HEADER " [TestSection\x00]\n", ERROR_BAD_SECTION_NAME_LINE, 3, FALSE },
{ STD_HEADER " [Test\x00Section]\n", ERROR_BAD_SECTION_NAME_LINE, 3, FALSE },
{ "garbage1\ngarbage2\n[abc]\n" STD_HEADER, ERROR_EXPECTED_SECTION_NAME, 1, FALSE },
{ "garbage1\ngarbage2\n[Strings]\n" STD_HEADER, 0, 0, FALSE },
{ ";comment\ngarbage1\ngarbage2\n[abc]\n" STD_HEADER, ERROR_EXPECTED_SECTION_NAME, 2, FALSE },
{ ";comment\ngarbage1\ngarbage2\n[Strings]\n" STD_HEADER, 0, 0, FALSE },
{ " \t\ngarbage1\ngarbage2\n[abc]\n" STD_HEADER, ERROR_EXPECTED_SECTION_NAME, 2, FALSE },
{ " \t\ngarbage1\ngarbage2\n[Strings]\n" STD_HEADER, 0, 0, FALSE },
{ "garbage1\ngarbage2\n" STD_HEADER "[abc]\n", ERROR_EXPECTED_SECTION_NAME, 1, FALSE },
{ "garbage1\ngarbage2\n" STD_HEADER "[Strings]\n", 0, 0, FALSE },
{ ";comment\ngarbage1\ngarbage2\n" STD_HEADER "[abc]\n", ERROR_EXPECTED_SECTION_NAME, 2, FALSE },
{ ";comment\ngarbage1\ngarbage2\n" STD_HEADER "[Strings]\n", 0, 0, FALSE },
{ " \t\ngarbage1\ngarbage2\n" STD_HEADER "[abc]\n", ERROR_EXPECTED_SECTION_NAME, 2, FALSE },
{ " \t\ngarbage1\ngarbage2\n" STD_HEADER "[Strings]\n", 0, 0, FALSE },
};
static void test_invalid_files(void)
......
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