Oops, it's my stupid bug.

Ah, this actually makes sense.  The setfcaps usage() statement does

        for (i=0; _cap_names[i]; i++) {
                printf...

so it expects _cap_names to end with a terminating NULL, but that
doesn't seem to be the case in cap_names.h in libcap.

KaiGai, perhaps setfcaps should do something like

diff setfcaps.c.orig setfcaps.c
25c25
<     for (i=0; _cap_names[i]; i++)
---
    for (i=0; i<__CAP_BITS; i++)

I fixed the matter as follows:

[EMAIL PROTECTED] libcap-1.10.kg]$ env LANG=C svn diff -r2:3
Index: libcap/_makenames.c
===================================================================
--- libcap/_makenames.c (revision 2)
+++ libcap/_makenames.c (revision 3)
@@ -45,6 +45,7 @@
           "#define __CAP_BITS   %d\n"
           "\n"
           "#ifdef LIBCAP_PLEASE_INCLUDE_ARRAY\n"
+          "  int const _cap_names_num = __CAP_BITS;\n"
           "  char const *_cap_names[__CAP_BITS] = {\n", maxcaps);

     for (i=0; i<maxcaps; ++i) {
Index: libcap/include/sys/capability.h
===================================================================
--- libcap/include/sys/capability.h     (revision 2)
+++ libcap/include/sys/capability.h     (revision 3)
@@ -113,6 +113,7 @@
 extern int capgetp(pid_t pid, cap_t cap_d);
 extern int capsetp(pid_t pid, cap_t cap_d);
 extern char const *_cap_names[];
+extern int const _cap_names_num;

 #endif /* !defined(_POSIX_SOURCE) */

Index: progs/setfcaps.c
===================================================================
--- progs/setfcaps.c    (revision 2)
+++ progs/setfcaps.c    (revision 3)
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <sys/capability.h>

+extern int const _cap_names_num;
 extern char const *_cap_names[];

 static void usage() {
@@ -21,8 +22,8 @@
     int i;

     fputs(message, stderr);
-    for (i=0; _cap_names[i]; i++)
-       fprintf(stderr, "%s%s", i%4==0 ? "\n\t" : ", ", _cap_names[i]);
+    for (i=0; i < _cap_names_num; i++)
+        fprintf(stderr, "%s%s", i%4==0 ? "\n\t" : ", ", _cap_names[i]);
     fputc('\n', stderr);
     exit(0);
 }
[EMAIL PROTECTED] libcap-1.10.kg]$

Because '__CAP_BITS' is decided at compiling time, I think it's not
appropriate to indicate the length of _cap_names[] which is linked
at run time.
Therefore, I add a new integer variable _cap_names_num to represent
the length of _cap_names at run time.

You can download it from http://www.kaigai.gr.jp/index.php?FrontPage#b556e50d

Thanks,
--
KaiGai Kohei <[EMAIL PROTECTED]>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to