From e819fdf7d31733089b809ec2e1126330cb3e069f Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 15 Feb 2017 17:24:14 +0000 Subject: [PATCH 2/4] activation test: Fix time-of-check/time-of-use bug waiting to happen Creating a directory is atomic, stat'ing it to see whether to remove it is very much not. Signed-off-by: Simon McVittie --- bus/activation.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/bus/activation.c b/bus/activation.c index 517af1ec..a104276f 100644 --- a/bus/activation.c +++ b/bus/activation.c @@ -2441,21 +2441,8 @@ out: static dbus_bool_t init_service_reload_test (DBusString *dir) { - DBusStat stat_buf; - - if (!_dbus_stat (dir, &stat_buf, NULL)) - { - if (!_dbus_create_directory (dir, NULL)) - return FALSE; - } - else - { - if (!test_remove_directory (dir)) - return FALSE; - - if (!_dbus_create_directory (dir, NULL)) - return FALSE; - } + if (!_dbus_create_directory (dir, NULL)) + return FALSE; /* Create one initial file */ if (!test_create_service_file (dir, SERVICE_FILE_1, SERVICE_NAME_1, "exec-1")) @@ -2643,6 +2630,9 @@ bus_activation_service_reload_test (const DBusString *test_data_dir) /* Do nothing? */ } + if (!cleanup_service_reload_test (&directory)) + goto out; + /* Do OOM tests */ if (!init_service_reload_test (&directory)) _dbus_assert_not_reached ("could not initiate service reload test"); -- 2.11.0