From afb17b8c007a49d93b0d30936b2d65af1bfdb039 Mon Sep 17 00:00:00 2001 From: "Andrew G. Morgan" Date: Thu, 16 Oct 2008 17:54:25 -0700 Subject: Another corner case not gracefully handled by cap_to_text. This shows up when you try to run getpcaps on a system still running with 32-bit capabilities. The output is very verbose for a process with no capabilities. Now it yields '='. Signed-off-by: Andrew G. Morgan --- libcap/cap_text.c | 7 +++++-- libcap/libcap.h | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libcap/cap_text.c b/libcap/cap_text.c index 2b81b1f..42fb685 100644 --- a/libcap/cap_text.c +++ b/libcap/cap_text.c @@ -365,9 +365,12 @@ char *cap_to_text(cap_t caps, ssize_t *length_p) for (n = cap_maxbits-1; n > __CAP_BITS; n--) histo[getstateflags(caps, n)]++; - /* find which combination of capability sets shares the most bits */ + /* find which combination of capability sets shares the most bits + we bias to preferring non-set (m=0) with the >= 0 test. Failing + to do this causes strange things to happen with older systems + that don't know about bits 32+. */ for (m=t=7; t--; ) - if (histo[t] > histo[m]) + if (histo[t] >= histo[m]) m = t; /* capture remaining bits - selecting m from only the unnamed bits, diff --git a/libcap/libcap.h b/libcap/libcap.h index 0c652ec..1e66f98 100644 --- a/libcap/libcap.h +++ b/libcap/libcap.h @@ -155,14 +155,14 @@ struct _cap_struct { #include # define _cap_debug(f, x...) do { \ - fprintf(stderr, __FUNCTION__ "(" __FILE__ ":%d): ", __LINE__); \ + fprintf(stderr, "%s(%s:%d): ", __FUNCTION__, __FILE__, __LINE__); \ fprintf(stderr, f, ## x); \ fprintf(stderr, "\n"); \ } while (0) # define _cap_debugcap(s, c, set) do { \ unsigned _cap_index; \ - fprintf(stderr, __FUNCTION__ "(" __FILE__ ":%d): " s, __LINE__); \ + fprintf(stderr, "%s(%s:%d): %s", __FUNCTION__, __FILE__, __LINE__, s); \ for (_cap_index=_LIBCAP_CAPABILITY_U32S; _cap_index-- > 0; ) { \ fprintf(stderr, "%08x", (c).u[_cap_index].flat[set]); \ } \ -- cgit v1.2.1