summaryrefslogtreecommitdiff
path: root/src/libsystemd-bus/test-bus-error.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-30 19:45:32 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-30 19:47:46 +0100
commit79f8d3d2ce51e992493f2d354a5764262c9d564a (patch)
treeea3b33286bed0f01d9f390def4d02b281b178247 /src/libsystemd-bus/test-bus-error.c
parentb57bdedc87c763aba1b5e8dc5396bfa3ac7d5086 (diff)
bus: support temporarily const errors that don't need to be freed but require deep copies
This should fix issues with incorrectly copying bus error messages out of sd_bus_message objects. Original bug found by: Djalal Harouni
Diffstat (limited to 'src/libsystemd-bus/test-bus-error.c')
-rw-r--r--src/libsystemd-bus/test-bus-error.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libsystemd-bus/test-bus-error.c b/src/libsystemd-bus/test-bus-error.c
index 9c0f4e0158..16c75a3f69 100644
--- a/src/libsystemd-bus/test-bus-error.c
+++ b/src/libsystemd-bus/test-bus-error.c
@@ -26,6 +26,12 @@
int main(int argc, char *argv[]) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL, second = SD_BUS_ERROR_NULL;
+ const sd_bus_error const_error = SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_FILE_EXISTS, "const error");
+ const sd_bus_error temporarily_const_error = {
+ .name = SD_BUS_ERROR_ACCESS_DENIED,
+ .message = "oh! no",
+ ._need_free = -1
+ };
assert_se(!sd_bus_error_is_set(&error));
assert_se(sd_bus_error_set(&error, SD_BUS_ERROR_NOT_SUPPORTED, "xxx") == -ENOTSUP);
@@ -45,7 +51,10 @@ int main(int argc, char *argv[]) {
assert_se(sd_bus_error_is_set(&error));
assert_se(!sd_bus_error_is_set(&second));
+ assert_se(second._need_free == 0);
+ assert_se(error._need_free > 0);
assert_se(sd_bus_error_copy(&second, &error) == -ENOENT);
+ assert_se(second._need_free > 0);
assert_se(streq(error.name, second.name));
assert_se(streq(error.message, second.message));
assert_se(sd_bus_error_get_errno(&second) == ENOENT);
@@ -53,6 +62,28 @@ int main(int argc, char *argv[]) {
assert_se(sd_bus_error_is_set(&second));
sd_bus_error_free(&error);
+ sd_bus_error_free(&second);
+
+ assert_se(!sd_bus_error_is_set(&second));
+ assert_se(const_error._need_free == 0);
+ assert_se(sd_bus_error_copy(&second, &const_error) == -EEXIST);
+ assert_se(second._need_free == 0);
+ assert_se(streq(const_error.name, second.name));
+ assert_se(streq(const_error.message, second.message));
+ assert_se(sd_bus_error_get_errno(&second) == EEXIST);
+ assert_se(sd_bus_error_has_name(&second, SD_BUS_ERROR_FILE_EXISTS));
+ assert_se(sd_bus_error_is_set(&second));
+ sd_bus_error_free(&second);
+
+ assert_se(!sd_bus_error_is_set(&second));
+ assert_se(temporarily_const_error._need_free < 0);
+ assert_se(sd_bus_error_copy(&second, &temporarily_const_error) == -EACCES);
+ assert_se(second._need_free > 0);
+ assert_se(streq(temporarily_const_error.name, second.name));
+ assert_se(streq(temporarily_const_error.message, second.message));
+ assert_se(sd_bus_error_get_errno(&second) == EACCES);
+ assert_se(sd_bus_error_has_name(&second, SD_BUS_ERROR_ACCESS_DENIED));
+ assert_se(sd_bus_error_is_set(&second));
assert_se(!sd_bus_error_is_set(&error));
assert_se(sd_bus_error_set_const(&error, "Posix.Error.EUCLEAN", "Hallo") == -EUCLEAN);