--- src/context.c~ 2003-05-08 16:36:53.000000000 -0400 +++ src/context.c 2003-07-13 20:52:27.000000000 -0400 @@ -18,12 +18,12 @@ * 4 colon-separated components and no whitespace. */ context_t -context_new(char *str) +context_new(const char *str) { int i,count; context_private_t *n = (context_private_t*) malloc(sizeof(context_private_t)); context_t result = (context_t) malloc(sizeof(context_s_t)); - char *p,*tok; + const char *p,*tok; if ( n == 0 || result == 0 ) { goto err; } n->current_str = n->component[0] = n->component[1] = n->component[2] = @@ -42,6 +42,8 @@ for ( i = 0, tok = str; *tok; i++ ) { for ( p = tok; *p && *p != ':'; p++ ) { /* empty */ } n->component[i] = (char*) malloc(p-tok+1); + if (n->component[i] == 0) + goto err; strncpy(n->component[i],tok,p-tok); n->component[i][p-tok] = '\0'; tok = *p ? p+1 : p; @@ -115,7 +117,7 @@ /* Returns nonzero iff failed */ -static int set_comp(context_private_t* n,int index,char *str) +static int set_comp(context_private_t* n,int index, const char *str) { char *t = (char*) malloc(strlen(str)+1); char *p; @@ -134,7 +136,7 @@ } #define def_get(name,tag) \ -char * context_ ## name ## _get(context_t context) \ +const char * context_ ## name ## _get(context_t context) \ { \ context_private_t *n = context->ptr; \ return n->component[tag]; \ @@ -146,7 +148,7 @@ def_get(role,COMP_ROLE) #define def_set(name,tag) \ -int context_ ## name ## _set(context_t context, char* str) \ +int context_ ## name ## _set(context_t context, const char* str) \ { \ return set_comp(context->ptr,tag,str);\ } @@ -155,7 +157,7 @@ def_set(role,COMP_ROLE) def_set(user,COMP_USER) -int context_range_set(context_t context,char* str) +int context_range_set(context_t context,const char* str) { context_private_t *n = context->ptr; if ( ! n->component[COMP_RANGE] ) { --- include/selinux/context.h~ 2003-05-08 16:36:51.000000000 -0400 +++ include/selinux/context.h 2003-07-13 20:52:42.000000000 -0400 @@ -13,7 +13,7 @@ /* Return a new context initialized to a context string */ -extern context_t context_new(char *); +extern context_t context_new(const char *); /* * Return a pointer to the string value of the context_t @@ -28,16 +28,16 @@ /* Get a pointer to the string value of a context component */ -extern char* context_type_get(context_t); -extern char* context_range_get(context_t); -extern char* context_role_get(context_t); -extern char* context_user_get(context_t); +extern const char* context_type_get(context_t); +extern const char* context_range_get(context_t); +extern const char* context_role_get(context_t); +extern const char* context_user_get(context_t); /* Set a context component. Returns nonzero if unsuccessful */ -extern int context_type_set(context_t,char*); -extern int context_range_set(context_t,char*); -extern int context_role_set(context_t,char*); -extern int context_user_set(context_t,char*); +extern int context_type_set(context_t,const char*); +extern int context_range_set(context_t,const char*); +extern int context_role_set(context_t,const char*); +extern int context_user_set(context_t,const char*); #endif --- src/get_context_list.c~ 2003-05-09 07:44:50.000000000 -0400 +++ src/get_context_list.c 2003-07-13 20:55:04.000000000 -0400 @@ -37,7 +37,7 @@ int length) { char *current_line; - char *ptr, *ptr2; + char *ptr, *ptr2 = NULL; int found = 0; char *cc_str = 0; int cc_len = 0; --- src/get_default_type.c~ 2003-05-09 08:59:47.000000000 -0400 +++ src/get_default_type.c 2003-07-13 20:55:33.000000000 -0400 @@ -28,7 +28,7 @@ char** type) { char buf[250]; - char *ptr, *end, *t; + char *ptr = "", *end, *t; int len; int found = 0;