Skip to content

Commit 3a59dbc

Browse files
authored
Merge pull request #85 from mrc0mmand/read-annotations
fuzz: respect the `org.freedesktop.DBus.Method.NoReply` annotation
2 parents f8d2443 + 6e1ee19 commit 3a59dbc

File tree

8 files changed

+34
-4
lines changed

8 files changed

+34
-4
lines changed

.github/workflows/run-tests.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ if [[ "$TYPE" == valgrind ]]; then
77
dfuzzer=("valgrind" "--leak-check=full" "--show-leak-kinds=definite" "--errors-for-leak-kinds=definite" "--error-exitcode=42" "dfuzzer")
88
fi
99

10+
# CI specific suppressions for issues already fixed in upstream
11+
sudo sed -i '/\[org.freedesktop.systemd1\]/a \
12+
org.freedesktop.systemd1.Manager:Reexecute Fixed by https://github.com/systemd/systemd/pull/23328 \
13+
' /etc/dfuzzer.conf
14+
1015
sudo systemctl daemon-reload
1116

1217
# Test if we can list activatable dbus services as well
@@ -35,6 +40,10 @@ EOF
3540
"${dfuzzer[@]}" -f inputs.txt -s -v -n org.freedesktop.dfuzzerServer -o /org/freedesktop/dfuzzerObject -i org.freedesktop.dfuzzerInterface -t df_crash_on_leeroy && false
3641
rm -f inputs.txt
3742

43+
# Test if we respect the org.freedesktop.DBus.Method.NoReply annotation
44+
"${dfuzzer[@]}" -s -v -n org.freedesktop.dfuzzerServer -o /org/freedesktop/dfuzzerObject -i org.freedesktop.dfuzzerInterface -t df_noreply && false
45+
"${dfuzzer[@]}" -s -v -n org.freedesktop.dfuzzerServer -o /org/freedesktop/dfuzzerObject -i org.freedesktop.dfuzzerInterface -t df_noreply_expected
46+
3847
sudo systemctl stop dfuzzer-test-server
3948

4049
# dfuzzer should return 0 by default when services it tests time out

src/dfuzzer-test-server.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ static const gchar introspection_xml[] =
6060
" <method name='df_noreply'>"
6161
" <arg type='t' name='lol' direction='in'/>"
6262
" </method>"
63+
" <method name='df_noreply_expected'>"
64+
" <arg type='ag' name='in' direction='in'/>"
65+
" <annotation name='org.freedesktop.DBus.Method.NoReply' value='true'/>"
66+
" </method>"
6367
" <method name='df_variant_crash'>"
6468
" <arg type='v' name='variant' direction='in'/>"
6569
" </method>"
@@ -127,8 +131,8 @@ static void handle_method_call(
127131
g_dbus_method_invocation_return_value(invocation, g_variant_new("()"));
128132
} else if (g_strcmp0(method_name, "df_hang") == 0)
129133
pause();
130-
else if (g_strcmp0(method_name, "df_noreply") == 0)
131-
return;
134+
else if (g_strcmp0(method_name, "df_noreply") == 0 || g_strcmp0(method_name, "df_noreply_expected") == 0)
135+
g_dbus_method_invocation_return_dbus_error(invocation, "org.freedesktop.DBus.Error.NoReply", "org.freedesktop.DBus.Error.NoReply");
132136
else if (g_strcmp0(method_name, "df_complex_sig_1") == 0) {
133137
gchar *str = NULL;
134138
unsigned u;

src/dfuzzer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ int df_fuzz(GDBusConnection *dcon, const char *name, const char *object, const c
533533
dbus_method.name = strdup(m->name);
534534
dbus_method.signature = df_method_get_full_signature(m);
535535
dbus_method.returns_value = !!*(m->out_args);
536+
dbus_method.expect_reply = df_method_returns_reply(m);
536537
dbus_method.fuzz_on_str_len = (strstr(dbus_method.signature, "s") || strstr(dbus_method.signature, "v"));
537538

538539
// tests for method

src/dfuzzer.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ org.freedesktop.systemd1.Manager:Halt destructive
3131
org.freedesktop.systemd1.Manager:KExec destructive
3232
org.freedesktop.systemd1.Manager:PowerOff destructive
3333
org.freedesktop.systemd1.Manager:Reboot destructive
34-
org.freedesktop.systemd1.Manager:Reexecute FIXME: disconnects systemd from the bus
3534
org.freedesktop.systemd1.Manager:RefUnit destructive
3635
org.freedesktop.systemd1.Manager:UnrefUnit destructive
3736
Freeze destructive

src/fuzz.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,9 @@ static int df_fuzz_call_method(const struct df_dbus_method *method, GVariant *va
591591
if (dbus_error) {
592592
// if process does not respond
593593
if (strcmp(dbus_error, "org.freedesktop.DBus.Error.NoReply") == 0)
594-
return -1;
594+
/* If the method is annotated as "NoReply", don't consider
595+
* not replying as an error */
596+
return method->expect_reply ? -1 : 0;
595597
else if (strcmp(dbus_error, "org.freedesktop.DBus.Error.Timeout") == 0) {
596598
sleep(10); // wait for tested process; processing
597599
// of longer inputs may take a longer time

src/fuzz.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct df_dbus_method {
3232
char *name;
3333
char *signature;
3434
gboolean returns_value;
35+
gboolean expect_reply;
3536

3637
int fuzz_on_str_len;
3738
};

src/introspection.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,16 @@ char *df_method_get_full_signature(const GDBusMethodInfo *method)
102102
return r;
103103
}
104104

105+
gboolean df_method_returns_reply(const GDBusMethodInfo *method)
106+
{
107+
const gchar *annotation_str;
108+
109+
assert(method);
110+
111+
annotation_str = g_dbus_annotation_info_lookup(method->annotations,
112+
"org.freedesktop.DBus.Method.NoReply");
113+
if (!isempty(annotation_str) && g_strcmp0(annotation_str, "true") == 0)
114+
return FALSE;
115+
116+
return TRUE;
117+
}

src/introspection.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222

2323
GDBusNodeInfo *df_get_interface_info(GDBusProxy *dproxy, const char *interface, GDBusInterfaceInfo **ret_iinfo);
2424
char *df_method_get_full_signature(const GDBusMethodInfo *method);
25+
gboolean df_method_returns_reply(const GDBusMethodInfo *method);
2526

2627
#endif

0 commit comments

Comments
 (0)