Skip to contentSkip to conversation

libselinux-3 (reviewed)

PATCH Bastian Blank 2 participants 2 messages Nov 29, 2003 – Dec 1, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

hi folks

this patch fixes following problems:
- size_t vs. int, ssize_t
- unsigned int vs. int
files: src/*

bastian

Signature · 3 lines
Lots of people drink from the wrong bottle sometimes.
		-- Edith Keeler, "The City on the Edge of Forever",
		   stardate unknown
get_context_list.c +8 -8
@@ -36,13 +36,13 @@
 	       an entry is found, and a 1 is returned otherwise.
 */
 static int find_line (FILE *infile, security_context_t con, char *line, 
-                      int length)
+                      size_t length)
 {
     char *current_line;
     char *ptr, *ptr2 = NULL;
     int found = 0;
     char *cc_str = 0;
-    int cc_len = 0;
+    size_t cc_len = 0;
 
     /* Skip the user field. */
     cc_str = index(con, ':');
@@ -53,12 +53,12 @@
     if (!cc_len)
 	    return -1;
 
-    current_line = (char *) malloc (length);
+    current_line = malloc (length);
     if (!current_line)
 	    return (-1);
 
     while (!feof (infile)) {
 	if (!fgets(current_line, length, infile)) {
 		free(current_line);
 		return -1;
 	}
@@ -119,9 +119,9 @@
                              int pri_length)
 {
     char *ptr, *ptr2;
-    int length;
+    size_t length;
     security_context_t current_context;
-    int current_context_len;
+    size_t current_context_len;
     int count = 0;
 
     ptr = instr;
@@ -205,7 +205,7 @@
 {
     FILE *config_file;    /* The configuration file                    */
     char *fname = 0;      /* The name of the user's configuration file */
-    int fname_len;        /* The length of fname                       */
+    size_t fname_len;     /* The length of fname                       */
     struct passwd *pwd;   /* The user's passwd structure               */
     int retval;           /* The return value                          */
 
@@ -218,7 +218,7 @@
             return -1;
         }
         fname_len = strlen (pwd->pw_dir) + 20;
-        fname = (char *) malloc (fname_len);
+        fname = malloc (fname_len);
         if (!fname)
         {
             return -1;
@@ -366,13 +366,13 @@
 	if (!ptr)
 		return -1;
 	plen = strlen(ptr);
 	if (buf[plen-1] == '\n') 
 		buf[plen-1] = 0;
 
 	nlen = strlen(user)+1+plen+1;
 	*newcon = malloc(nlen);
 	rc = snprintf(*newcon, nlen, "%s:%s", user, ptr);
-	if (rc < 0 || rc >= nlen) {
+	if (rc < 0 || (size_t) rc >= nlen) {
 		free(*newcon);
 		*newcon = 0;
 		return -1;
Makefile +2 -2
Index: src/Makefile
===================================================================
@@ -25,10 +26,10 @@
 	ln -sf $@ $(TARGET) 
 
 %.o:  %.c
-	$(CC) -o $@ -c $(CFLAGS) $<
+	$(CC) $(CFLAGS) -c -o $@ $<
 
 %.lo:  %.c
-	$(CC) -o $@ -c -fPIC $(CFLAGS) $<
+	$(CC) $(CFLAGS) -fPIC -c -o $@ $<
 
 install: all
 	test -d $(LIBDIR) || install -m 755 -d $(LIBDIR)

Index: src/fsetfilecon.c
===================================================================

compute_av.c +1 -1
Index: src/compute_av.c
===================================================================
@@ -16,7 +16,7 @@
 			struct av_decision *avd)
 {
 	char *buf;
-	unsigned int len;
+	size_t len;
 	int fd, ret;
 
 	fd = open(SELINUXMNT "access", O_RDWR);
helpers.c +2 -2
Index: src/helpers.c
===================================================================
@@ -23,7 +23,7 @@
 
 security_class_t string_to_security_class(const char *s)
 {
-	int val;
+	unsigned int val;
 
 	if (isdigit(s[0])) {
 		val = atoi(s);
@@ -45,7 +45,7 @@
 {
         char          **common_pts = 0;
         access_vector_t common_base = 0;
-        int             i, i2, perm;
+        unsigned int             i, i2, perm;
  
  
         if (av == 0) {

Index: src/lsetfilecon.c
===================================================================

compute_user.c +2 -2
Index: src/compute_user.c
===================================================================
@@ -16,8 +16,8 @@
 	char **ary;
 	char *buf, *ptr;
 	size_t size;
-	int fd, ret, i;
-	unsigned int nel;
+	int fd, ret;
+	unsigned int i, nel;
 
 	fd = open(SELINUXMNT "user", O_RDWR);
 	if (fd < 0)
get_default_type.c +1 -1
Index: src/get_default_type.c
===================================================================
@@ -29,7 +29,7 @@
 {
     char buf[250];
     char *ptr = "", *end, *t;
-    int len;
+    size_t len;
     int found = 0;
 
     len = strlen(role);
context.c +4 -3
Index: src/context.c
===================================================================
@@ -93,14 +93,15 @@
 context_str(context_t context)
 {
         context_private_t *n = context->ptr;
-        int i, total;
+        int i;
+        size_t total = 0;
         conditional_free(&n->current_str);
-        for ( i = total = 0; i < 4; i++ ) {
+        for ( i = 0; i < 4; i++ ) {
                 if ( n->component[i] ) {
                         total += strlen(n->component[i])+1;
                 }
         }
-        n->current_str = (char*) malloc(total);
+        n->current_str = malloc(total);
         if ( n->current_str != 0 ) {
                 strcpy(n->current_str,n->component[0]);
                 strcat(n->current_str,":");
#1 lore raw
Quoted 6 lines · Bastian Blank

hi folks

this patch fixes following problems:
- size_t vs. int, ssize_t
- unsigned int vs. int
files: src/*

Thanks, merged.

Signature · 8 lines
Stephen Smalley <[email protected]>
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.