summaryrefslogtreecommitdiff
path: root/DevTools/IPCCompiler
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-16 14:11:35 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-16 14:13:09 +0200
commitcd298446328af0d71a74d31f750fb1326689a3fe (patch)
treeacdf2f3444e7cb22325ed60ed13cea5476300e2a /DevTools/IPCCompiler
parentf7a75598bb738ae9f9c8293efe161a5724fbb127 (diff)
downloadserenity-cd298446328af0d71a74d31f750fb1326689a3fe.zip
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.
Diffstat (limited to 'DevTools/IPCCompiler')
-rw-r--r--DevTools/IPCCompiler/main.cpp23
1 files changed, 23 insertions, 0 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<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;