aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2023-06-24 22:47:45 -0700
committerAndrew G. Morgan <morgan@kernel.org>2023-06-24 22:47:45 -0700
commit4ffb54079cde63894292b67c5cf1b62deb02a330 (patch)
tree874b1057210176e724b1c2f3dca903155dacbe70
parentac8d461a2ce1ca3ea68099d75b5e6fd09f48fcef (diff)
downloadlibcap-4ffb54079cde63894292b67c5cf1b62deb02a330.tar.gz
Add a check for a capabability of all spaces.
Address user report of confusing behavior by adding a check to setcap for a "<space...>" capability not meaning "-r". Another suggestion from https://bugzilla.kernel.org/show_bug.cgi?id=217592 Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r--progs/setcap.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/progs/setcap.c b/progs/setcap.c
index 598272c..79cd2ce 100644
--- a/progs/setcap.c
+++ b/progs/setcap.c
@@ -4,6 +4,7 @@
* This sets/verifies the capabilities of a given file.
*/
+#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
@@ -168,6 +169,17 @@ int main(int argc, char **argv)
text = *argv;
}
+ int non_space = 0;
+ for (int j = 0; text[j]; j++) {
+ if (!isspace(text[j])) {
+ non_space = 1;
+ break;
+ }
+ }
+ if (!non_space) {
+ fprintf(stderr, "empty space is an invalid capability, did you mean -r?\n");
+ exit(1);
+ }
cap_d = cap_from_text(text);
if (cap_d == NULL) {
perror("fatal error");