Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Amer Al Shanawany and committed by
Shuah Khan
b0df3062 051f2226

+15 -4
+9 -3
tools/testing/selftests/capabilities/test_execve.c
··· 82 82 { 83 83 uid_t outer_uid; 84 84 gid_t outer_gid; 85 - int i; 85 + int i, ret; 86 86 bool have_outer_privilege; 87 87 88 88 outer_uid = getuid(); ··· 97 97 ksft_exit_fail_msg("setresuid - %s\n", strerror(errno)); 98 98 99 99 // 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 + 101 104 for (i = 0; i < CAP_LAST_CAP; i++) 102 105 if (capng_have_capability(CAPNG_PERMITTED, i)) 103 106 capng_update(CAPNG_ADD, CAPNG_EFFECTIVE, i); ··· 210 207 211 208 static int do_tests(int uid, const char *our_path) 212 209 { 210 + int ret; 213 211 bool have_outer_privilege = create_and_enter_ns(uid); 214 212 215 213 int ourpath_fd = open(our_path, O_RDONLY | O_DIRECTORY); ··· 254 250 ksft_exit_fail_msg("chmod - %s\n", strerror(errno)); 255 251 } 256 252 257 - capng_get_caps_process(); 253 + ret = capng_get_caps_process(); 254 + if (ret == -1) 255 + ksft_exit_fail_msg("capng_get_caps_process failed\n"); 258 256 259 257 /* Make sure that i starts out clear */ 260 258 capng_update(CAPNG_DROP, CAPNG_INHERITABLE, CAP_NET_BIND_SERVICE);
+6 -1
tools/testing/selftests/capabilities/validate_cap.c
··· 28 28 int main(int argc, char **argv) 29 29 { 30 30 const char *atsec = ""; 31 + int ret; 31 32 32 33 /* 33 34 * Be careful just in case a setgid or setcapped copy of this ··· 45 44 atsec = " (AT_SECURE is not set)"; 46 45 #endif 47 46 48 - capng_get_caps_process(); 47 + ret = capng_get_caps_process(); 48 + if (ret == -1) { 49 + ksft_print_msg("capng_get_caps_process failed\n"); 50 + return 1; 51 + } 49 52 50 53 if (capng_have_capability(CAPNG_EFFECTIVE, CAP_NET_BIND_SERVICE) != bool_arg(argv, 1)) { 51 54 ksft_print_msg("Wrong effective state%s\n", atsec);