various fixes for libselinux
PATCH 1/1 various fixes for libselinux
Hi,
Attached is a patch which fixes various things in libselinux; It adds a bunch of consts to the context.h API, handles a missed out-of-memory condition, and cleans up some -Wall compile warnings.
context.c renamed from context.c~ +8 -6
@@ -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 ] ) {
selinux/context.h renamed from selinux/context.h~ +9 -9
@@ -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
get_context_list.c renamed from get_context_list.c~ +1 -1
@@ -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 ;
get_default_type.c renamed from get_default_type.c~ +1 -1
@@ -28,7 +28,7 @@ char** type) {char buf[250 ]; -char *ptr, *end, *t; +char *ptr ="" , *end, *t;int len;int found =0 ;
Quoted 3 lines · Colin Walters
Attached is a patch which fixes various things in libselinux; It adds a bunch of consts to the
context.hAPI, handles a missed out-of-memory condition, and cleans up some -Wall compile warnings.
This patch has been committed to the sourceforge CVS tree. Also added another const for a local variable set to a parameter to avoid a compiler warning introduced by the const on the parameter.
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.