summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2017-02-12 23:10:05 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2017-02-13 12:41:19 +0100
commit11c843e980a4f45bd058863ab4397dcc27fb2b52 (patch)
treecdbd194f2b48b8f8769df2585ed17a9c3f19f987
parent09e6818d01eaa14cbce7bac12abe521c46d92893 (diff)
downloadvala-11c843e980a4f45bd058863ab4397dcc27fb2b52.tar.gz
gdbus: Handle errors when extracting fds from dbus messages
On the right situations (eg. fd exhaustion), both g_dbus_message_get_unix_fd_list() and g_unix_fd_list_get() should be considered failable here. Add proper error handling to avoid triggering glib warnings. https://bugzilla.gnome.org/show_bug.cgi?id=778540
-rw-r--r--codegen/valagdbusclientmodule.vala3
-rw-r--r--codegen/valagdbusmodule.vala33
-rw-r--r--codegen/valagdbusservermodule.vala3
3 files changed, 31 insertions, 8 deletions
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index 6fdda8a50..ac45b58cd 100644
--- a/codegen/valagdbusclientmodule.vala
+++ b/codegen/valagdbusclientmodule.vala
@@ -615,7 +615,6 @@ public class Vala.GDBusClientModule : GDBusModule {
ccode.add_expression (builder_init);
if (uses_fd) {
- ccode.add_declaration ("GUnixFDList", new CCodeVariableDeclarator ("*_fd_list"));
ccode.add_assignment (new CCodeIdentifier ("_fd_list"), new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_new")));
}
@@ -772,6 +771,8 @@ public class Vala.GDBusClientModule : GDBusModule {
if (uses_fd) {
ccode.add_declaration ("gint", new CCodeVariableDeclarator.zero ("_fd_index", new CCodeConstant ("0")));
+ ccode.add_declaration ("GUnixFDList*", new CCodeVariableDeclarator ("_fd_list"));
+ ccode.add_declaration ("gint", new CCodeVariableDeclarator ("_fd"));
}
foreach (Parameter param in m.get_parameters ()) {
diff --git a/codegen/valagdbusmodule.vala b/codegen/valagdbusmodule.vala
index 8f10daa02..0a6404ad8 100644
--- a/codegen/valagdbusmodule.vala
+++ b/codegen/valagdbusmodule.vala
@@ -220,21 +220,42 @@ public class Vala.GDBusModule : GVariantModule {
var fd_list = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_message_get_unix_fd_list"));
fd_list.add_argument (message_expr);
- var fd = new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_get"));
- fd.add_argument (fd_list);
- fd.add_argument (new CCodeIdentifier ("_fd_index"));
- fd.add_argument (new CCodeConstant ("NULL"));
+ var fd_var = new CCodeIdentifier ("_fd");
- var stream = create_from_file_descriptor (type, fd);
+ var stream = create_from_file_descriptor (type, fd_var);
if (stream != null) {
+ var fd_list_var = new CCodeIdentifier ("_fd_list");
+
+ var fd = new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_get"));
+ fd.add_argument (fd_list_var);
+ fd.add_argument (new CCodeIdentifier ("_fd_index"));
+ fd.add_argument (error_expr);
+
+ ccode.add_assignment (fd_list_var, fd_list);
+ ccode.open_if (fd_list_var);
+
var get_fd = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_iter_next"));
get_fd.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, iter_expr));
get_fd.add_argument (new CCodeConstant ("\"h\""));
get_fd.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_fd_index")));
ccode.add_expression (get_fd);
+ ccode.add_assignment (fd_var, fd);
+ ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.GREATER_THAN_OR_EQUAL, fd_var, new CCodeConstant ("0")));
+
ccode.add_assignment (target_expr, stream);
- may_fail = false;
+ may_fail = true;
+
+ ccode.close ();
+
+ ccode.add_else ();
+ var set_error = new CCodeFunctionCall (new CCodeIdentifier ("g_set_error_literal"));
+ set_error.add_argument (error_expr);
+ set_error.add_argument (new CCodeIdentifier ("G_IO_ERROR"));
+ set_error.add_argument (new CCodeIdentifier ("G_IO_ERROR_FAILED"));
+ set_error.add_argument (new CCodeConstant ("\"FD List is NULL\""));
+ ccode.add_expression (set_error);
+ ccode.close ();
} else {
read_expression (type, iter_expr, target_expr, sym, error_expr, out may_fail);
}
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index 0df78c24c..e3cbc6e4f 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -62,6 +62,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
bool uses_fd = dbus_method_uses_file_descriptor (m);
if (uses_fd) {
cfile.add_include ("gio/gunixfdlist.h");
+ ccode.add_declaration ("GUnixFDList*", new CCodeVariableDeclarator ("_fd_list"));
}
bool uses_error = false;
@@ -93,6 +94,7 @@ public class Vala.GDBusServerModule : GDBusClientModule {
if (!ready) {
if (uses_fd) {
ccode.add_declaration ("gint", new CCodeVariableDeclarator.zero ("_fd_index", new CCodeConstant ("0")));
+ ccode.add_declaration ("gint", new CCodeVariableDeclarator ("_fd"));
}
foreach (Parameter param in m.get_parameters ()) {
@@ -257,7 +259,6 @@ public class Vala.GDBusServerModule : GDBusClientModule {
ccode.add_expression (builder_init);
if (uses_fd) {
- ccode.add_declaration ("GUnixFDList", new CCodeVariableDeclarator ("*_fd_list"));
ccode.add_assignment (new CCodeIdentifier ("_fd_list"), new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_new")));
}