LibIDL: Fix use-after-free in GenerateWindowOrWorkerInterfaces

`lexical_bases` was storing `StringView`s into `ByteString`s returned
from `LexicalPath::string()` that might no longer exist.

(cherry picked from commit c3783cf3bd8261b6f456cd9f796cc6a0b03096ee)
This commit is contained in:
Jonne Ransijn 2024-11-15 23:43:04 +01:00 committed by Nico Weber
parent ca09ed4b37
commit 3eabeaa198
4 changed files with 8 additions and 9 deletions

View file

@ -21,7 +21,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
{ {
Core::ArgsParser args_parser; Core::ArgsParser args_parser;
StringView path; StringView path;
Vector<StringView> import_base_paths; Vector<ByteString> import_base_paths;
StringView output_path = "-"sv; StringView output_path = "-"sv;
StringView depfile_path; StringView depfile_path;
StringView depfile_prefix; StringView depfile_prefix;

View file

@ -356,11 +356,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
VERIFY(!paths.is_empty()); VERIFY(!paths.is_empty());
VERIFY(!base_paths.is_empty()); VERIFY(!base_paths.is_empty());
Vector<StringView> lexical_bases; Vector<ByteString> lexical_bases;
for (auto const& base_path : base_paths) { for (auto const& base_path : base_paths) {
VERIFY(!base_path.is_empty()); VERIFY(!base_path.is_empty());
LexicalPath lexical_path(base_path); lexical_bases.append(base_path);
lexical_bases.append(lexical_path.string());
} }
// Read in all IDL files, we must own the storage for all of these for the lifetime of the program // Read in all IDL files, we must own the storage for all of these for the lifetime of the program

View file

@ -1250,7 +1250,7 @@ Interface& Parser::parse()
return interface; return interface;
} }
Parser::Parser(ByteString filename, StringView contents, Vector<StringView> import_base_paths) Parser::Parser(ByteString filename, StringView contents, Vector<ByteString> import_base_paths)
: import_base_paths(move(import_base_paths)) : import_base_paths(move(import_base_paths))
, filename(move(filename)) , filename(move(filename))
, input(contents) , input(contents)
@ -1258,7 +1258,7 @@ Parser::Parser(ByteString filename, StringView contents, Vector<StringView> impo
{ {
} }
Parser::Parser(Parser* parent, ByteString filename, StringView contents, Vector<StringView> import_base_paths) Parser::Parser(Parser* parent, ByteString filename, StringView contents, Vector<ByteString> import_base_paths)
: import_base_paths(move(import_base_paths)) : import_base_paths(move(import_base_paths))
, filename(move(filename)) , filename(move(filename))
, input(contents) , input(contents)

View file

@ -17,7 +17,7 @@ namespace IDL {
class Parser { class Parser {
public: public:
Parser(ByteString filename, StringView contents, Vector<StringView> import_base_paths); Parser(ByteString filename, StringView contents, Vector<ByteString> import_base_paths);
Interface& parse(); Interface& parse();
Vector<ByteString> imported_files() const; Vector<ByteString> imported_files() const;
@ -35,7 +35,7 @@ private:
Yes, Yes,
}; };
Parser(Parser* parent, ByteString filename, StringView contents, Vector<StringView> import_base_path); Parser(Parser* parent, ByteString filename, StringView contents, Vector<ByteString> import_base_path);
void assert_specific(char ch); void assert_specific(char ch);
void assert_string(StringView expected); void assert_string(StringView expected);
@ -68,7 +68,7 @@ private:
ByteString parse_identifier_ending_with_space(); ByteString parse_identifier_ending_with_space();
ByteString parse_identifier_ending_with_space_or(auto... possible_terminating_characters); ByteString parse_identifier_ending_with_space_or(auto... possible_terminating_characters);
Vector<StringView> import_base_paths; Vector<ByteString> import_base_paths;
ByteString filename; ByteString filename;
StringView input; StringView input;
LineTrackingLexer lexer; LineTrackingLexer lexer;