diff options
author | Lennart Poettering <lennart@poettering.net> | 2009-08-07 01:33:14 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2009-10-17 00:28:31 +0200 |
commit | 1f179e0f27f656ed3c5d1ee2ac5e1bbfe26d9d94 (patch) | |
tree | f239fdaf9e72954e153d33b88e0c1fd2a04d90bf /dbus/dbus-message-util.c | |
parent | 2ed34f69d4400f863835c4149be4ecb82ffe1c72 (diff) |
desktop-file: fix stat() race
_dbus_desktop_file_load() used to stat the desktop file before reading
it, to verify its size. This is both racy and unnecessary since
_dbus_file_get_contents() which it uses stats the file anyway -- does
that however in a race-free fashion with fstat() instead of stat().
This patch gets rid of the redundant stat(). Also, since the desktop
file change logic requires the mtime of the file it read we now export
that in _dbus_file_get_contents().
This patch probably breaks Win32 builds, but afaik those are broken
anyway.
Diffstat (limited to 'dbus/dbus-message-util.c')
-rw-r--r-- | dbus/dbus-message-util.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/dbus/dbus-message-util.c b/dbus/dbus-message-util.c index a56fcc49..df371e4c 100644 --- a/dbus/dbus-message-util.c +++ b/dbus/dbus-message-util.c @@ -221,7 +221,7 @@ check_have_valid_message (DBusMessageLoader *loader) #endif record_validity_seen (DBUS_VALID); - + retval = TRUE; failed: @@ -246,7 +246,7 @@ check_invalid_message (DBusMessageLoader *loader, } record_validity_seen (loader->corruption_reason); - + if (expected_validity != DBUS_INVALID_FOR_UNKNOWN_REASON && loader->corruption_reason != expected_validity) { @@ -312,7 +312,7 @@ check_loader_results (DBusMessageLoader *loader, */ if (_dbus_message_loader_get_is_corrupted (loader)) record_validity_seen (loader->corruption_reason); - + return TRUE; } else @@ -336,7 +336,7 @@ dbus_internal_do_not_use_load_message_file (const DBusString *filename, retval = FALSE; _dbus_verbose ("Loading raw %s\n", _dbus_string_get_const_data (filename)); - if (!_dbus_file_get_contents (data, filename, &error)) + if (!_dbus_file_get_contents (data, filename, NULL, &error)) { _dbus_warn ("Could not load message file %s: %s\n", _dbus_string_get_const_data (filename), @@ -560,7 +560,7 @@ process_test_subdir (const DBusString *test_base_dir, _dbus_warn ("Could not load %s, message builder language no longer supported\n", _dbus_string_get_const_data (&filename)); } - + _dbus_verbose ("Skipping non-.message file %s\n", _dbus_string_get_const_data (&filename)); _dbus_string_free (&full_path); @@ -621,27 +621,27 @@ dbus_internal_do_not_use_foreach_message_file (const char *test_d retval = FALSE; _dbus_string_init_const (&test_directory, test_data_dir); - + if (!process_test_subdir (&test_directory, "valid-messages", DBUS_VALID, func, user_data)) goto failed; check_memleaks (); - + if (!process_test_subdir (&test_directory, "invalid-messages", DBUS_INVALID_FOR_UNKNOWN_REASON, func, user_data)) goto failed; check_memleaks (); - + if (!process_test_subdir (&test_directory, "incomplete-messages", DBUS_VALID_BUT_INCOMPLETE, func, user_data)) goto failed; check_memleaks (); - + retval = TRUE; - + failed: _dbus_string_free (&test_directory); @@ -831,7 +831,7 @@ verify_test_message (DBusMessage *message) if (our_uint16 != 0x123) _dbus_assert_not_reached ("16-bit uints differ!"); - + if (our_int != -0x12345678) _dbus_assert_not_reached ("integers differ!"); @@ -936,7 +936,7 @@ verify_test_message (DBusMessage *message) _dbus_assert_not_reached ("string array had wrong values"); dbus_free_string_array (our_string_array); - + if (dbus_message_iter_next (&iter)) _dbus_assert_not_reached ("Didn't reach end of arguments"); } @@ -1246,7 +1246,7 @@ _dbus_message_test (const char *test_data_dir) /* Message loader test */ dbus_message_lock (message); loader = _dbus_message_loader_new (); - + /* check ref/unref */ _dbus_message_loader_ref (loader); _dbus_message_loader_unref (loader); @@ -1354,7 +1354,7 @@ _dbus_message_test (const char *test_data_dir) /* Bytes needed to demarshal empty message: 0 (more) */ _dbus_assert (dbus_message_demarshal_bytes_needed ("", 0) == 0); - + /* Bytes needed to demarshal invalid message: -1 (error). */ _dbus_assert (dbus_message_demarshal_bytes_needed (garbage_header, DBUS_MINIMUM_HEADER_SIZE) == -1); @@ -1401,10 +1401,10 @@ _dbus_message_test (const char *test_data_dir) int count; reset_validities_seen (); - + count = 0; _dbus_message_data_iter_init (&diter); - + while (_dbus_message_data_iter_get_and_next (&diter, &mdata)) { @@ -1437,7 +1437,7 @@ _dbus_message_test (const char *test_data_dir) return dbus_internal_do_not_use_foreach_message_file (test_data_dir, (DBusForeachMessageFileFunc) dbus_internal_do_not_use_try_message_file, - NULL); + NULL); } #endif /* DBUS_BUILD_TESTS */ |