mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-29 06:02:07 +03:00
LibIPC: Allow opt-in UTF-8 validation on message parameters
You can now mark String message parameters with the [UTF8] attribute. This will cause the generated decoder to perform UTF-8 validation and reject the message if the given parameter is not a valid UTF-8 string. This frees up the receiving side from having to do this validation at a higher level.
This commit is contained in:
parent
f7a75598bb
commit
cd29844632
Notes:
sideshowbarker
2024-07-19 06:36:35 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/cd298446328
@ -35,6 +35,7 @@
|
||||
//#define GENERATE_DEBUG_CODE
|
||||
|
||||
struct Parameter {
|
||||
Vector<String> attributes;
|
||||
String type;
|
||||
String name;
|
||||
};
|
||||
@ -127,6 +128,23 @@ int main(int argc, char** argv)
|
||||
consume_whitespace();
|
||||
if (peek() == ')')
|
||||
break;
|
||||
if (peek() == '[') {
|
||||
consume_one();
|
||||
for (;;) {
|
||||
if (peek() == ']') {
|
||||
consume_one();
|
||||
consume_whitespace();
|
||||
break;
|
||||
}
|
||||
if (peek() == ',') {
|
||||
consume_one();
|
||||
consume_whitespace();
|
||||
}
|
||||
auto attribute = extract_while([](char ch) { return ch != ']' && ch != ','; });
|
||||
parameter.attributes.append(attribute);
|
||||
consume_whitespace();
|
||||
}
|
||||
}
|
||||
parameter.type = extract_while([](char ch) { return !isspace(ch); });
|
||||
consume_whitespace();
|
||||
parameter.name = extract_while([](char ch) { return !isspace(ch) && ch != ',' && ch != ')'; });
|
||||
@ -226,6 +244,7 @@ int main(int argc, char** argv)
|
||||
out() << "#pragma once";
|
||||
out() << "#include <AK/BufferStream.h>";
|
||||
out() << "#include <AK/OwnPtr.h>";
|
||||
out() << "#include <AK/Utf8View.h>";
|
||||
out() << "#include <LibGfx/Color.h>";
|
||||
out() << "#include <LibGfx/Rect.h>";
|
||||
out() << "#include <LibGfx/ShareableBitmap.h>";
|
||||
@ -312,6 +331,10 @@ int main(int argc, char** argv)
|
||||
out() << " " << parameter.type << " " << parameter.name << " = " << initial_value << ";";
|
||||
out() << " if (!decoder.decode(" << parameter.name << "))";
|
||||
out() << " return nullptr;";
|
||||
if (parameter.attributes.contains_slow("UTF8")) {
|
||||
out() << " if (!Utf8View(" << parameter.name << ").validate())";
|
||||
out() << " return nullptr;";
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder builder;
|
||||
|
@ -1,4 +1,4 @@
|
||||
endpoint ClipboardClient = 804
|
||||
{
|
||||
ClipboardDataChanged(String mime_type) =|
|
||||
ClipboardDataChanged([UTF8] String mime_type) =|
|
||||
}
|
||||
|
@ -2,6 +2,6 @@ endpoint ClipboardServer = 802
|
||||
{
|
||||
Greet() => (i32 client_id)
|
||||
|
||||
GetClipboardData() => (i32 shbuf_id, i32 data_size, String mime_type)
|
||||
SetClipboardData(i32 shbuf_id, i32 data_size, String mime_type) => ()
|
||||
GetClipboardData() => (i32 shbuf_id, i32 data_size, [UTF8] String mime_type)
|
||||
SetClipboardData(i32 shbuf_id, i32 data_size, [UTF8] String mime_type) => ()
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ endpoint NotificationServer = 95
|
||||
// Basic protocol
|
||||
Greet() => (i32 client_id)
|
||||
|
||||
ShowNotification(String text, String title, Gfx::ShareableBitmap icon) => ()
|
||||
ShowNotification([UTF8] String text, [UTF8] String title, Gfx::ShareableBitmap icon) => ()
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ endpoint WindowClient = 4
|
||||
ScreenRectChanged(Gfx::Rect rect) =|
|
||||
|
||||
WM_WindowRemoved(i32 wm_id, i32 client_id, i32 window_id) =|
|
||||
WM_WindowStateChanged(i32 wm_id, i32 client_id, i32 window_id, bool is_active, bool is_minimized, bool is_frameless, i32 window_type, String title, Gfx::Rect rect) =|
|
||||
WM_WindowStateChanged(i32 wm_id, i32 client_id, i32 window_id, bool is_active, bool is_minimized, bool is_frameless, i32 window_type, [UTF8] String title, Gfx::Rect rect) =|
|
||||
WM_WindowIconBitmapChanged(i32 wm_id, i32 client_id, i32 window_id, i32 icon_buffer_id, Gfx::Size icon_size) =|
|
||||
WM_WindowRectChanged(i32 wm_id, i32 client_id, i32 window_id, Gfx::Rect rect) =|
|
||||
|
||||
@ -30,7 +30,7 @@ endpoint WindowClient = 4
|
||||
DragAccepted() =|
|
||||
DragCancelled() =|
|
||||
|
||||
DragDropped(i32 window_id, Gfx::Point mouse_position, String text, String data_type, String data) =|
|
||||
DragDropped(i32 window_id, Gfx::Point mouse_position, [UTF8] String text, String data_type, String data) =|
|
||||
|
||||
UpdateSystemTheme(i32 system_theme_buffer_id) =|
|
||||
|
||||
|
@ -5,7 +5,7 @@ endpoint WindowServer = 2
|
||||
CreateMenubar() => (i32 menubar_id)
|
||||
DestroyMenubar(i32 menubar_id) => ()
|
||||
|
||||
CreateMenu(String menu_title) => (i32 menu_id)
|
||||
CreateMenu([UTF8] String menu_title) => (i32 menu_id)
|
||||
DestroyMenu(i32 menu_id) => ()
|
||||
|
||||
AddMenuToMenubar(i32 menubar_id, i32 menu_id) => ()
|
||||
@ -17,17 +17,17 @@ endpoint WindowServer = 2
|
||||
i32 menu_id,
|
||||
i32 identifier,
|
||||
i32 submenu_id,
|
||||
String text,
|
||||
[UTF8] String text,
|
||||
bool enabled,
|
||||
bool checkable,
|
||||
bool checked,
|
||||
String shortcut,
|
||||
[UTF8] String shortcut,
|
||||
i32 icon_buffer_id,
|
||||
bool exclusive) => ()
|
||||
|
||||
AddMenuSeparator(i32 menu_id) => ()
|
||||
|
||||
UpdateMenuItem(i32 menu_id, i32 identifier, i32 submenu_id, String text, bool enabled, bool checkable, bool checked, String shortcut) => ()
|
||||
UpdateMenuItem(i32 menu_id, i32 identifier, i32 submenu_id, [UTF8] String text, bool enabled, bool checkable, bool checked, [UTF8] String shortcut) => ()
|
||||
|
||||
CreateWindow(
|
||||
Gfx::Rect rect,
|
||||
@ -41,13 +41,13 @@ endpoint WindowServer = 2
|
||||
Gfx::Size base_size,
|
||||
Gfx::Size size_increment,
|
||||
i32 type,
|
||||
String title,
|
||||
[UTF8] String title,
|
||||
i32 parent_window_id) => (i32 window_id)
|
||||
|
||||
DestroyWindow(i32 window_id) => (Vector<i32> destroyed_window_ids)
|
||||
|
||||
SetWindowTitle(i32 window_id, String title) => ()
|
||||
GetWindowTitle(i32 window_id) => (String title)
|
||||
SetWindowTitle(i32 window_id, [UTF8] String title) => ()
|
||||
GetWindowTitle(i32 window_id) => ([UTF8] String title)
|
||||
|
||||
SetWindowRect(i32 window_id, Gfx::Rect rect) => (Gfx::Rect rect)
|
||||
GetWindowRect(i32 window_id) => (Gfx::Rect rect)
|
||||
@ -84,10 +84,10 @@ endpoint WindowServer = 2
|
||||
SetWindowOverrideCursor(i32 window_id, i32 cursor_type) => ()
|
||||
SetWindowCustomOverrideCursor(i32 window_id, Gfx::ShareableBitmap cursor) => ()
|
||||
|
||||
StartDrag(String text, String data_type, String data, i32 bitmap_id, Gfx::Size bitmap_size) => (bool started)
|
||||
StartDrag([UTF8] String text, String data_type, String data, i32 bitmap_id, Gfx::Size bitmap_size) => (bool started)
|
||||
|
||||
SetSystemTheme(String theme_path, String theme_name) => (bool success)
|
||||
GetSystemTheme() => (String theme_name)
|
||||
SetSystemTheme(String theme_path, [UTF8] String theme_name) => (bool success)
|
||||
GetSystemTheme() => ([UTF8] String theme_name)
|
||||
|
||||
SetWindowBaseSizeAndSizeIncrement(i32 window_id, Gfx::Size base_size, Gfx::Size size_increment) => ()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user