From af544bd0c0ccc5f901a719a0f1b3ae599c214730 Mon Sep 17 00:00:00 2001 From: Rafal Krypa Date: Fri, 6 Mar 2015 10:46:09 +0100 Subject: [PATCH] security-manager-tests: use libsmack functions for operations on socket labels Use smack_set_label_for_file() and smack_new_label_from_file() instead of plain fsetxattr() and fgetxattr(). These libsmack functions have been recently provided by libsmack 1.1. This change also fixes a bug in the tests. We incorrectly expected the value from fgetxattr() to be null-terminated. It was before kernel 3.20, but that was incorrect for the kernel to do. With most current kernels the test failed. Libsmack functions do the null-termination for us, so the test is working again. Change-Id: Ifc1820cddad0c5acbe49f3c98e622b07acc31358 Signed-off-by: Rafal Krypa --- .../security_manager_tests.cpp | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/security-manager-tests/security_manager_tests.cpp b/tests/security-manager-tests/security_manager_tests.cpp index 6ab415e..27db73d 100644 --- a/tests/security-manager-tests/security_manager_tests.cpp +++ b/tests/security-manager-tests/security_manager_tests.cpp @@ -523,30 +523,28 @@ RUNNER_CHILD_TEST_SMACK(security_manager_03_set_label_from_appid) result = bind(sock, (struct sockaddr*) &sockaddr, sizeof(struct sockaddr_un)); RUNNER_ASSERT_ERRNO_MSG(result == 0, "bind failed"); //Set socket label to something different than expecedLabel - result = fsetxattr(sock, XATTR_NAME_SMACKIPIN, socketLabel, - strlen(socketLabel), 0); + result = smack_set_label_for_file(sock, XATTR_NAME_SMACKIPIN, socketLabel); RUNNER_ASSERT_ERRNO_MSG(result == 0, "Can't set socket label. Result: " << result); - result = fsetxattr(sock, XATTR_NAME_SMACKIPOUT, socketLabel, - strlen(socketLabel), 0); + result = smack_set_label_for_file(sock, XATTR_NAME_SMACKIPOUT, socketLabel); RUNNER_ASSERT_ERRNO_MSG(result == 0, "Can't set socket label. Result: " << result); Api::setProcessLabel(app_id); - char value[SMACK_LABEL_LEN + 1]; - ssize_t size; - size = fgetxattr(sock, XATTR_NAME_SMACKIPIN, value, sizeof(value)); - RUNNER_ASSERT_ERRNO_MSG(size != -1, "fgetxattr failed: " << value); - result = expected_label.compare(value); + result = smack_new_label_from_file(sock, XATTR_NAME_SMACKIPIN, &label); + RUNNER_ASSERT_ERRNO_MSG(result != -1, "smack_new_label_from_file failed: " << label); + labelPtr.reset(label); + result = expected_label.compare(label); RUNNER_ASSERT_MSG(result == 0, "Socket label is incorrect. Expected: " << - expected_label << " Actual: " << value); + expected_label << " Actual: " << label); - size = fgetxattr(sock, XATTR_NAME_SMACKIPOUT, value, sizeof(value)); - RUNNER_ASSERT_ERRNO_MSG(size != -1, "fgetxattr failed: " << value); - result = expected_label.compare(value); + result = smack_new_label_from_file(sock, XATTR_NAME_SMACKIPOUT, &label); + RUNNER_ASSERT_ERRNO_MSG(result != -1, "smack_new_label_from_file failed: " << label); + labelPtr.reset(label); + result = expected_label.compare(label); RUNNER_ASSERT_MSG(result == 0, "Socket label is incorrect. Expected: " << - expected_label << " Actual: " << value); + expected_label << " Actual: " << label); result = smack_new_label_from_self(&label); RUNNER_ASSERT_MSG(result >= 0, -- 2.7.4