Blame SOURCES/libcap-ng-0.8.1-signed-unsigned-fix.patch

d781c9
diff -ru a/src/cap-ng.c b/src/cap-ng.c
d781c9
--- a/src/cap-ng.c
d781c9
+++ b/src/cap-ng.c
d781c9
@@ -46,7 +46,7 @@
d781c9
 #endif
d781c9
 
d781c9
 # define hidden __attribute__ ((visibility ("hidden")))
d781c9
-int last_cap hidden = -1;
d781c9
+unsigned int last_cap hidden = 0;
d781c9
 /*
d781c9
  * Some milestones of when things became available:
d781c9
  * 2.6.24 kernel	XATTR_NAME_CAPS
d781c9
@@ -65,7 +65,7 @@
d781c9
 // Local defines
d781c9
 #define MASK(x) (1U << (x))
d781c9
 #ifdef PR_CAPBSET_DROP
d781c9
-#define UPPER_MASK ~(unsigned)((~0U)<<(last_cap-31))
d781c9
+#define UPPER_MASK ~((~0U)<<(last_cap-31))
d781c9
 #else
d781c9
 // For v1 systems UPPER_MASK will never be used
d781c9
 #define UPPER_MASK (unsigned)(~0U)
d781c9
@@ -73,7 +73,7 @@
d781c9
 
d781c9
 // Re-define cap_valid so its uniform between V1 and V3
d781c9
 #undef cap_valid
d781c9
-#define cap_valid(x) ((x) <= (unsigned int)last_cap)
d781c9
+#define cap_valid(x) ((x) <= last_cap)
d781c9
 
d781c9
 // If we don't have the xattr library, then we can't
d781c9
 // compile-in file system capabilities
d781c9
@@ -174,6 +174,26 @@
d781c9
 #ifdef HAVE_PTHREAD_H
d781c9
 	pthread_atfork(NULL, NULL, deinit);
d781c9
 #endif
d781c9
+	// Detect last cap
d781c9
+	if (last_cap == 0) {
d781c9
+		int fd;
d781c9
+
d781c9
+		fd = open("/proc/sys/kernel/cap_last_cap", O_RDONLY);
d781c9
+		if (fd >= 0) {
d781c9
+			char buf[8];
d781c9
+			int num = read(fd, buf, sizeof(buf) - 1);
d781c9
+			if (num > 0) {
d781c9
+				buf[num] = 0;
d781c9
+				errno = 0;
d781c9
+				unsigned int val = strtoul(buf, NULL, 10);
d781c9
+				if (errno == 0)
d781c9
+					last_cap = val;
d781c9
+			}
d781c9
+			close(fd);
d781c9
+		}
d781c9
+		if (last_cap == 0)
d781c9
+			last_cap = CAP_LAST_CAP;
d781c9
+	}
d781c9
 }
d781c9
 
d781c9
 static void init(void)
d781c9
@@ -199,26 +219,6 @@
d781c9
 #else
d781c9
 	m.hdr.pid = (unsigned)getpid();
d781c9
 #endif
d781c9
-	// Detect last cap
d781c9
-	if (last_cap == -1) {
d781c9
-		int fd;
d781c9
-
d781c9
-		fd = open("/proc/sys/kernel/cap_last_cap", O_RDONLY);
d781c9
-		if (fd >= 0) {
d781c9
-			char buf[8];
d781c9
-			int num = read(fd, buf, sizeof(buf) - 1);
d781c9
-			if (num > 0) {
d781c9
-				buf[num] = 0;
d781c9
-				errno = 0;
d781c9
-				int val = strtoul(buf, NULL, 10);
d781c9
-				if (errno == 0)
d781c9
-					last_cap = val;
d781c9
-			}
d781c9
-			close(fd);
d781c9
-		}
d781c9
-		if (last_cap == -1)
d781c9
-			last_cap = CAP_LAST_CAP;
d781c9
-	}
d781c9
 	m.state = CAPNG_ALLOCATED;
d781c9
 }
d781c9
 
d781c9
@@ -478,7 +478,7 @@
d781c9
 		if (CAPNG_INHERITABLE & type)
d781c9
 			v1_update(action, capability, &m.data.v1.inheritable);
d781c9
 	} else {
d781c9
-		int idx;
d781c9
+		unsigned int idx;
d781c9
 
d781c9
 		if (capability > 31) {
d781c9
 			idx = capability>>5;
d781c9
@@ -545,7 +545,7 @@
d781c9
 		memcpy(&state, &m, sizeof(state)); /* save state */
d781c9
 		capng_get_caps_process();
d781c9
 		if (capng_have_capability(CAPNG_EFFECTIVE, CAP_SETPCAP)) {
d781c9
-			int i;
d781c9
+			unsigned int i;
d781c9
 			memcpy(&m, &state, sizeof(m)); /* restore state */
d781c9
 			rc = 0;
d781c9
 			for (i=0; i <= last_cap && rc == 0; i++)
d781c9
@@ -602,7 +602,7 @@
d781c9
 #ifndef VFS_CAP_U32
d781c9
 	return -1;
d781c9
 #else
d781c9
-	int rc, size;
d781c9
+	int rc, size = 0;
d781c9
 	struct vfs_cap_data filedata;
d781c9
 	struct stat buf;
d781c9
 
d781c9
@@ -1010,7 +1010,7 @@
d781c9
 
d781c9
 char *capng_print_caps_text(capng_print_t where, capng_type_t which)
d781c9
 {
d781c9
-	int i, once = 0, cnt = 0;
d781c9
+	unsigned int i, once = 0, cnt = 0;
d781c9
 	char *ptr = NULL;
d781c9
 
d781c9
 	if (m.state < CAPNG_INIT)
d781c9
diff -ru a/src/lookup_table.c b/src/lookup_table.c
d781c9
--- a/src/lookup_table.c
d781c9
+++ b/src/lookup_table.c
d781c9
@@ -29,10 +29,10 @@
d781c9
 
d781c9
 
d781c9
 #define hidden __attribute__ ((visibility ("hidden")))
d781c9
-extern int last_cap hidden;
d781c9
+extern unsigned int last_cap hidden;
d781c9
 
d781c9
 #undef cap_valid
d781c9
-#define cap_valid(x) ((x) <= (unsigned int)last_cap)
d781c9
+#define cap_valid(x) ((x) <= last_cap)
d781c9
 
d781c9
 
d781c9
 struct transtab {
d781c9
diff -ru a/src/test/lib_test.c b/src/test/lib_test.c
d781c9
--- a/src/test/lib_test.c
d781c9
+++ b/src/test/lib_test.c
d781c9
@@ -29,7 +29,7 @@
d781c9
 #include <fcntl.h>
d781c9
 #include <sys/stat.h>
d781c9
 
d781c9
-int get_last_cap(void)
d781c9
+static unsigned int get_last_cap(void)
d781c9
 {
d781c9
 	int fd;
d781c9
 
d781c9
@@ -41,17 +41,19 @@
d781c9
 		int num = read(fd, buf, sizeof(buf));
d781c9
 		if (num > 0) {
d781c9
 			errno = 0;
d781c9
-			int val = strtoul(buf, NULL, 10);
d781c9
+			unsigned int val = strtoul(buf, NULL, 10);
d781c9
 			if (errno == 0)
d781c9
 				return val;
d781c9
 		}
d781c9
+		close(fd);
d781c9
 	}
d781c9
 	return CAP_LAST_CAP;
d781c9
 }
d781c9
 
d781c9
 int main(void)
d781c9
 {
d781c9
-	int rc, i, len, last = get_last_cap();
d781c9
+	int rc;
d781c9
+	unsigned int i, len, last = get_last_cap();
d781c9
 	char *text;
d781c9
 	void *saved;
d781c9
 
d781c9
@@ -127,7 +129,7 @@
d781c9
 			abort();
d781c9
 		}
d781c9
 		name = capng_capability_to_name(i);
d781c9
-		if (name == NULL) { 
d781c9
+		if (name == NULL) {
d781c9
 			printf("Failed converting capability %d to name\n", i);
d781c9
 			abort();
d781c9
 		}