From cd298446328af0d71a74d31f750fb1326689a3fe Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 16 May 2020 14:11:35 +0200 Subject: [PATCH] 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. --- DevTools/IPCCompiler/main.cpp | 23 +++++++++++++++++++ Services/Clipboard/ClipboardClient.ipc | 2 +- Services/Clipboard/ClipboardServer.ipc | 4 ++-- .../NotificationServer/NotificationServer.ipc | 2 +- Services/WindowServer/WindowClient.ipc | 4 ++-- Services/WindowServer/WindowServer.ipc | 20 ++++++++-------- 6 files changed, 39 insertions(+), 16 deletions(-) diff --git a/DevTools/IPCCompiler/main.cpp b/DevTools/IPCCompiler/main.cpp index 8351e2da80..4a86508d7b 100644 --- a/DevTools/IPCCompiler/main.cpp +++ b/DevTools/IPCCompiler/main.cpp @@ -35,6 +35,7 @@ //#define GENERATE_DEBUG_CODE struct Parameter { + Vector 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 "; out() << "#include "; + out() << "#include "; out() << "#include "; out() << "#include "; out() << "#include "; @@ -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; diff --git a/Services/Clipboard/ClipboardClient.ipc b/Services/Clipboard/ClipboardClient.ipc index 4434c56f21..50d695e92a 100644 --- a/Services/Clipboard/ClipboardClient.ipc +++ b/Services/Clipboard/ClipboardClient.ipc @@ -1,4 +1,4 @@ endpoint ClipboardClient = 804 { - ClipboardDataChanged(String mime_type) =| + ClipboardDataChanged([UTF8] String mime_type) =| } diff --git a/Services/Clipboard/ClipboardServer.ipc b/Services/Clipboard/ClipboardServer.ipc index 4b419459ec..dc3dd4db28 100644 --- a/Services/Clipboard/ClipboardServer.ipc +++ b/Services/Clipboard/ClipboardServer.ipc @@ -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) => () } diff --git a/Services/NotificationServer/NotificationServer.ipc b/Services/NotificationServer/NotificationServer.ipc index f1ac5e13df..e342ebf2d3 100644 --- a/Services/NotificationServer/NotificationServer.ipc +++ b/Services/NotificationServer/NotificationServer.ipc @@ -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) => () } diff --git a/Services/WindowServer/WindowClient.ipc b/Services/WindowServer/WindowClient.ipc index ec04a2a91a..37e369de7e 100644 --- a/Services/WindowServer/WindowClient.ipc +++ b/Services/WindowServer/WindowClient.ipc @@ -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) =| diff --git a/Services/WindowServer/WindowServer.ipc b/Services/WindowServer/WindowServer.ipc index 9ac51fe983..dbd3c06957 100644 --- a/Services/WindowServer/WindowServer.ipc +++ b/Services/WindowServer/WindowServer.ipc @@ -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 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) => ()