Commit a54f5011 authored by Daiki Ueno's avatar Daiki Ueno Committed by Daiki Ueno

secret-file-collection: force little-endian in GVariant

As the GVariant serialization format does not record the original
endianness of integer values, we need to ensure that it doesn't change
between write and load.
parent 9adf3214
Pipeline #159776 passed with stages
in 9 minutes and 23 seconds
......@@ -287,7 +287,9 @@ on_load_contents (GObject *source_object,
GVariant *variant;
GVariant *salt_array;
guint32 salt_size;
guint32 iteration_count;
guint64 modified_time;
guint64 usage_count;
gconstpointer data;
gsize n_data;
GError *error = NULL;
......@@ -365,11 +367,18 @@ on_load_contents (GObject *source_object,
g_free,
contents);
g_variant_get (variant, "(u@ayutu@a(a{say}ay))",
&salt_size, &salt_array, &self->iteration_count,
&modified_time, &self->usage_count,
&salt_size, &salt_array, &iteration_count,
&modified_time, &usage_count,
&self->items);
salt_size = GUINT32_FROM_LE(salt_size);
iteration_count = GUINT32_FROM_LE(iteration_count);
modified_time = GUINT64_FROM_LE(modified_time);
usage_count = GUINT32_FROM_LE(usage_count);
self->iteration_count = iteration_count;
self->modified = g_date_time_new_from_unix_utc (modified_time);
self->usage_count = usage_count;
data = g_variant_get_fixed_array (salt_array, &n_data, sizeof(guint8));
g_assert (n_data == salt_size);
......@@ -796,11 +805,11 @@ secret_file_collection_write (SecretFileCollection *self,
g_bytes_get_size (self->salt),
sizeof(guint8));
variant = g_variant_new ("(u@ayutu@a(a{say}ay))",
g_bytes_get_size (self->salt),
GUINT32_TO_LE(g_bytes_get_size (self->salt)),
salt_array,
self->iteration_count,
g_date_time_to_unix (self->modified),
self->usage_count,
GUINT32_TO_LE(self->iteration_count),
GUINT64_TO_LE(g_date_time_to_unix (self->modified)),
GUINT32_TO_LE(self->usage_count),
self->items);
g_variant_get_data (variant); /* force serialize */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment