Skip to content

Commit

Permalink
Merge pull request #88 from mrc0mmand/followups
Browse files Browse the repository at this point in the history
fuzz: distinguish between reading/writing properties in logs
  • Loading branch information
evverx authored May 13, 2022
2 parents c6186d9 + de718c4 commit f43fe14
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 20 deletions.
27 changes: 25 additions & 2 deletions man/dfuzzer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,31 @@
<term><option>--method=<replaceable>NAME</replaceable></option></term>

<listitem><para>If provided, only method named <replaceable>NAME</replaceable> is tested.
Requires <option>-o/--object=</option> and <option>-i/--interface=</option> to be set as well.
</para></listitem>
Requires <option>-o/--object=</option> and <option>-i/--interface=</option> to be set as well.</para>

<para>Implies <option>--skip-properties</option>.</para></listitem>
</varlistentry>

<varlistentry>
<term><option>-p <replaceable>NAME</replaceable></option></term>
<term><option>--property=<replaceable>NAME</replaceable></option></term>

<listitem><para>If provided, only property named <replaceable>NAME</replaceable> is tested.
Requires <option>-o/--object=</option> and <option>-i/--interface=</option> to be set as well.</para>

<para>Implies <option>--skip-methods</option>.</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--skip-methods</option></term>

<listitem><para>Skip method testing and test only properties.</para></listitem>
</varlistentry>

<varlistentry>
<term><option>--skip-properties</option></term>

<listitem><para>Skip property testing and test only methods.</para></listitem>
</varlistentry>

<varlistentry>
Expand Down
8 changes: 5 additions & 3 deletions src/dfuzzer-test-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static const gchar introspection_xml[] =
" <property name='read_only' type='s' access='read'/>"
" <property name='write_only' type='s' access='write'/>"
" <property name='crash_on_write' type='i' access='write'/>"
" <property name='crash_on_read' type='a(gov)' access='read'/>"
" <property name='read_write' type='(iu)' access='readwrite'/>"
" </interface>"
"</node>";
Expand Down Expand Up @@ -180,11 +181,12 @@ static GVariant *handle_get_property(

g_printf("->[handle_get_property] %s\n", property_name);

if (g_str_equal(property_name, "read_only")) {
if (g_str_equal(property_name, "read_only"))
response = g_variant_new("(s)", prop_read_only);
} else if (g_str_equal(property_name, "read_write")) {
else if (g_str_equal(property_name, "crash_on_read"))
test_abort();
else if (g_str_equal(property_name, "read_write"))
response = g_variant_new("(iu)", prop_read_write.i, prop_read_write.u);
}

return response;
}
Expand Down
49 changes: 34 additions & 15 deletions src/fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ int df_fuzz_test_method(
df_debug(" Method: %s%s %s => %"G_GUINT64_FORMAT" iterations%s\n", ansi_bold(),
method->name, method->signature, iterations, ansi_normal());

df_verbose(" %s...", method->name);
df_verbose(" [M] %s...", method->name);

df_except_counter = 0;

Expand Down Expand Up @@ -709,11 +709,6 @@ int df_fuzz_test_property(GDBusConnection *dcon, const struct df_dbus_property *
g_autoptr(GDBusProxy) pproxy = NULL;
int r;

df_debug(" Property: %s%s %s => %"G_GUINT64_FORMAT" iterations%s\n", ansi_bold(),
property->name, property->signature, iterations, ansi_normal());

df_verbose(" [P] %s...", property->name);

/* Create a "property proxy"
* See: https://dbus.freedesktop.org/doc/dbus-specification.html#standard-interfaces-properties
*/
Expand All @@ -727,15 +722,34 @@ int df_fuzz_test_property(GDBusConnection *dcon, const struct df_dbus_property *
* For performance reasons read readable property only twice, since that
* should be enough to trigger most of the issues.
*/
for (guint8 i = 0; i < 2; i++) {
if (property->is_readable) {
iterations = 2;
if (property->is_readable) {
df_debug(" Property: %s%s %s (read) => %"G_GUINT64_FORMAT" iterations%s\n", ansi_bold(),
property->name, property->signature, iterations, ansi_normal());

df_verbose(" [P] %s (read)...", property->name);

for (guint8 i = 0; i < iterations; i++) {
r = df_fuzz_get_property(pproxy, interface, property);
if (r < 0) {
df_fail("%s %sFAIL%s [P] %s - unexpected response while reading a property\n",
ansi_cr(), ansi_red(), ansi_normal(), property->name);
return 1;
}
}

/* Check if the remote side is still alive */
r = df_check_if_exited(pid);
if (r < 0)
return df_fail_ret(-1, "Error while reading process' stat file: %m\n");
else if (r == 0) {
df_fail("%s %sFAIL%s [P] %s (read) - process %d exited\n",
ansi_cr(), ansi_red(), ansi_normal(), property->name, pid);
return 1;
}

df_verbose("%s %sPASS%s [P] %s (read)\n",
ansi_cr(), ansi_green(), ansi_normal(), property->name);
}

/* Try to write a random value to the property if it's writable
Expand All @@ -744,8 +758,13 @@ int df_fuzz_test_property(GDBusConnection *dcon, const struct df_dbus_property *
* dictionaries doing the "full" loop is mostly a waste of time.
*/
iterations = CLAMP(iterations, 1, 16);
for (guint64 i = 0; i < iterations; i++) {
if (property->is_writable) {
if (property->is_writable) {
df_debug(" Property: %s%s %s (write) => %"G_GUINT64_FORMAT" iterations%s\n", ansi_bold(),
property->name, property->signature, iterations, ansi_normal());

df_verbose(" [P] %s (write)...", property->name);

for (guint64 i = 0; i < iterations; i++) {
g_autoptr(GVariant) value = NULL;

/* Create a random GVariant based on method's signature */
Expand All @@ -757,7 +776,7 @@ int df_fuzz_test_property(GDBusConnection *dcon, const struct df_dbus_property *
value = g_variant_ref_sink(value);
r = df_fuzz_set_property(pproxy, interface, property, value);
if (r < 0) {
df_fail("%s %sFAIL%s [P] %s - unexpected response while writing to a property\n",
df_fail("%s %sFAIL%s [P] %s (write) - unexpected response while writing to a property\n",
ansi_cr(), ansi_red(), ansi_normal(), property->name);
return 1;
}
Expand All @@ -768,14 +787,14 @@ int df_fuzz_test_property(GDBusConnection *dcon, const struct df_dbus_property *
if (r < 0)
return df_fail_ret(-1, "Error while reading process' stat file: %m\n");
else if (r == 0) {
df_fail("%s %sFAIL%s [P] %s - process %d exited\n",
df_fail("%s %sFAIL%s [P] %s (write) - process %d exited\n",
ansi_cr(), ansi_red(), ansi_normal(), property->name, pid);
return 1;
}
}

df_verbose("%s %sPASS%s [P] %s\n",
ansi_cr(), ansi_green(), ansi_normal(), property->name);
df_verbose("%s %sPASS%s [P] %s (write)\n",
ansi_cr(), ansi_green(), ansi_normal(), property->name);
}

return 0;
}

0 comments on commit f43fe14

Please sign in to comment.