Skip to content

Commit b0df306

Browse files
Amer-shanawanyshuahkh
authored andcommitted
selftests/capabilities: fix warn_unused_result build warnings
Fix the following warnings by adding return check and error handling. test_execve.c: In function ‘do_tests’: test_execve.c:100:17: warning: ignoring return value of ‘capng_get_caps_process’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 100 | capng_get_caps_process(); | ^~~~~~~~~~~~~~~~~~~~~~~~ validate_cap.c: In function ‘main’: validate_cap.c:47:9: warning: ignoring return value of ‘capng_get_caps_process’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 47 | capng_get_caps_process(); | ^~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Amer Al Shanawany <amer.shanawany@gmail.com> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 051f222 commit b0df306

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

tools/testing/selftests/capabilities/test_execve.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static bool create_and_enter_ns(uid_t inner_uid)
8282
{
8383
uid_t outer_uid;
8484
gid_t outer_gid;
85-
int i;
85+
int i, ret;
8686
bool have_outer_privilege;
8787

8888
outer_uid = getuid();
@@ -97,7 +97,10 @@ static bool create_and_enter_ns(uid_t inner_uid)
9797
ksft_exit_fail_msg("setresuid - %s\n", strerror(errno));
9898

9999
// Re-enable effective caps
100-
capng_get_caps_process();
100+
ret = capng_get_caps_process();
101+
if (ret == -1)
102+
ksft_exit_fail_msg("capng_get_caps_process failed\n");
103+
101104
for (i = 0; i < CAP_LAST_CAP; i++)
102105
if (capng_have_capability(CAPNG_PERMITTED, i))
103106
capng_update(CAPNG_ADD, CAPNG_EFFECTIVE, i);
@@ -207,6 +210,7 @@ static void exec_validate_cap(bool eff, bool perm, bool inh, bool ambient)
207210

208211
static int do_tests(int uid, const char *our_path)
209212
{
213+
int ret;
210214
bool have_outer_privilege = create_and_enter_ns(uid);
211215

212216
int ourpath_fd = open(our_path, O_RDONLY | O_DIRECTORY);
@@ -250,7 +254,9 @@ static int do_tests(int uid, const char *our_path)
250254
ksft_exit_fail_msg("chmod - %s\n", strerror(errno));
251255
}
252256

253-
capng_get_caps_process();
257+
ret = capng_get_caps_process();
258+
if (ret == -1)
259+
ksft_exit_fail_msg("capng_get_caps_process failed\n");
254260

255261
/* Make sure that i starts out clear */
256262
capng_update(CAPNG_DROP, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE);

tools/testing/selftests/capabilities/validate_cap.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ static bool bool_arg(char **argv, int i)
2828
int main(int argc, char **argv)
2929
{
3030
const char *atsec = "";
31+
int ret;
3132

3233
/*
3334
* Be careful just in case a setgid or setcapped copy of this
@@ -44,7 +45,11 @@ int main(int argc, char **argv)
4445
atsec = " (AT_SECURE is not set)";
4546
#endif
4647

47-
capng_get_caps_process();
48+
ret = capng_get_caps_process();
49+
if (ret == -1) {
50+
ksft_print_msg("capng_get_caps_process failed\n");
51+
return 1;
52+
}
4853

4954
if (capng_have_capability(CAPNG_EFFECTIVE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 1)) {
5055
ksft_print_msg("Wrong effective state%s\n", atsec);

0 commit comments

Comments
 (0)