summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-sha.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-08-07 01:33:14 +0200
committerLennart Poettering <lennart@poettering.net>2009-10-17 00:28:31 +0200
commit1f179e0f27f656ed3c5d1ee2ac5e1bbfe26d9d94 (patch)
treef239fdaf9e72954e153d33b88e0c1fd2a04d90bf /dbus/dbus-sha.c
parent2ed34f69d4400f863835c4149be4ecb82ffe1c72 (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-sha.c')
-rw-r--r--dbus/dbus-sha.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/dbus/dbus-sha.c b/dbus/dbus-sha.c
index 04e353a0..03b098ba 100644
--- a/dbus/dbus-sha.c
+++ b/dbus/dbus-sha.c
@@ -500,7 +500,7 @@ _dbus_sha_compute (const DBusString *data,
goto error;
_dbus_string_free (&digest);
-
+
return TRUE;
error:
@@ -562,7 +562,7 @@ decode_compact_string (const DBusString *line,
int next;
long val;
int length_bytes;
-
+
offset = 0;
next = 0;
@@ -574,7 +574,7 @@ decode_compact_string (const DBusString *line,
}
_dbus_string_skip_blank (line, next, &next);
-
+
offset = next;
if (!_dbus_string_parse_int (line, offset, &val, &next))
{
@@ -582,7 +582,7 @@ decode_compact_string (const DBusString *line,
_dbus_string_get_const_data (line));
return FALSE;
}
-
+
if (!(val == 0 || val == 1))
{
fprintf (stderr, "the value 'b' must be 0 or 1, see sha-1/Readme.txt\n");
@@ -590,19 +590,19 @@ decode_compact_string (const DBusString *line,
}
_dbus_string_skip_blank (line, next, &next);
-
+
current_b = val;
n_bits = 0;
-
+
while (next < _dbus_string_get_length (line))
{
int total_bits;
-
+
offset = next;
if (_dbus_string_get_byte (line, offset) == '^')
break;
-
+
if (!_dbus_string_parse_int (line, offset, &val, &next))
{
fprintf (stderr, "could not parse bit count in compact string\n");
@@ -616,7 +616,7 @@ decode_compact_string (const DBusString *line,
int byte_containing_next_bit = n_bits / 8;
int bit_containing_next_bit = 7 - (n_bits % 8);
unsigned char old_byte;
-
+
if (byte_containing_next_bit >= _dbus_string_get_length (decoded))
{
if (!_dbus_string_set_length (decoded, byte_containing_next_bit + 1))
@@ -631,19 +631,19 @@ decode_compact_string (const DBusString *line,
current_b, byte_containing_next_bit,
bit_containing_next_bit, old_byte);
#endif
-
+
_dbus_string_set_byte (decoded, byte_containing_next_bit, old_byte);
-
+
++n_bits;
}
_dbus_string_skip_blank (line, next, &next);
-
+
current_b = !current_b;
}
length_bytes = (n_bits / 8 + ((n_bits % 8) ? 1 : 0));
-
+
if (_dbus_string_get_length (decoded) != length_bytes)
{
fprintf (stderr, "Expected length %d bytes %d bits for compact string, got %d bytes\n",
@@ -662,10 +662,10 @@ get_next_expected_result (DBusString *results,
dbus_bool_t retval;
retval = FALSE;
-
+
if (!_dbus_string_init (&line))
_dbus_assert_not_reached ("no memory");
-
+
next_iteration:
while (_dbus_string_pop_line (results, &line))
{
@@ -685,7 +685,7 @@ get_next_expected_result (DBusString *results,
else
{
int i;
-
+
if (!_dbus_string_move (&line, 0, result, 0))
_dbus_assert_not_reached ("no memory");
@@ -721,13 +721,13 @@ get_next_expected_result (DBusString *results,
++i;
}
-
+
break;
}
}
-
+
retval = TRUE;
-
+
/* out: */
_dbus_string_free (&line);
return retval;
@@ -748,7 +748,7 @@ process_test_data (const char *test_data_dir)
DBusError error = DBUS_ERROR_INIT;
retval = FALSE;
-
+
if (!_dbus_string_init (&tests_file))
_dbus_assert_not_reached ("no memory");
@@ -763,7 +763,7 @@ process_test_data (const char *test_data_dir)
if (!_dbus_string_init (&line))
_dbus_assert_not_reached ("no memory");
-
+
if (!_dbus_string_append (&tests_file, test_data_dir))
_dbus_assert_not_reached ("no memory");
@@ -778,7 +778,7 @@ process_test_data (const char *test_data_dir)
if (!_dbus_concat_dir_and_file (&results_file, &tmp))
_dbus_assert_not_reached ("no memory");
- if (!_dbus_file_get_contents (&tests, &tests_file, &error))
+ if (!_dbus_file_get_contents (&tests, &tests_file, NULL, &error))
{
fprintf (stderr, "could not load test data file %s: %s\n",
_dbus_string_get_const_data (&tests_file),
@@ -787,7 +787,7 @@ process_test_data (const char *test_data_dir)
goto out;
}
- if (!_dbus_file_get_contents (&results, &results_file, &error))
+ if (!_dbus_file_get_contents (&results, &results_file, NULL, &error))
{
fprintf (stderr, "could not load results data file %s: %s\n",
_dbus_string_get_const_data (&results_file), error.message);
@@ -819,7 +819,7 @@ process_test_data (const char *test_data_dir)
* we'd have to do a little bit more implementation
* to use those tests.
*/
-
+
printf (" (ending tests due to Type 3 tests seen - this is normal)\n");
break;
}
@@ -836,13 +836,13 @@ process_test_data (const char *test_data_dir)
dbus_bool_t success;
success = FALSE;
-
+
if (!_dbus_string_init (&next_line))
_dbus_assert_not_reached ("no memory");
if (!_dbus_string_init (&expected))
_dbus_assert_not_reached ("no memory");
-
+
if (!_dbus_string_init (&test))
_dbus_assert_not_reached ("no memory");
@@ -861,14 +861,14 @@ process_test_data (const char *test_data_dir)
_dbus_string_get_length (&line)))
_dbus_assert_not_reached ("no memory");
}
-
+
if (!decode_compact_string (&line, &test))
{
fprintf (stderr, "Failed to decode line %d as a compact string\n",
line_no);
goto failure;
}
-
+
if (!_dbus_sha_compute (&test, &result))
_dbus_assert_not_reached ("no memory for SHA-1 result");
@@ -877,9 +877,9 @@ process_test_data (const char *test_data_dir)
fprintf (stderr, "Failed to read an expected result\n");
goto failure;
}
-
+
if (!_dbus_string_equal (&result, &expected))
- {
+ {
fprintf (stderr, " for line %d got hash %s expected %s\n",
line_no,
_dbus_string_get_const_data (&result),
@@ -908,7 +908,7 @@ process_test_data (const char *test_data_dir)
printf ("Passed the %d SHA-1 tests in the test file\n",
success_count);
-
+
out:
_dbus_string_free (&tests_file);
_dbus_string_free (&results_file);
@@ -938,7 +938,7 @@ _dbus_sha_test (const char *test_data_dir)
}
else
printf ("No test data dir\n");
-
+
i = 0;
while (i < 256)
{