* [patch] various fixes for libselinux
@ 2003-07-14 1:05 Colin Walters
2003-07-15 21:07 ` Stephen Smalley
0 siblings, 1 reply; 2+ messages in thread
From: Colin Walters @ 2003-07-14 1:05 UTC (permalink / raw)
To: selinux
[-- Attachment #1: Type: text/plain, Size: 203 bytes --]
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.
[-- Attachment #2: various-fixes.patch --]
[-- Type: text/plain, Size: 4096 bytes --]
--- 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;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch] various fixes for libselinux
2003-07-14 1:05 [patch] various fixes for libselinux Colin Walters
@ 2003-07-15 21:07 ` Stephen Smalley
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Smalley @ 2003-07-15 21:07 UTC (permalink / raw)
To: Colin Walters; +Cc: selinux
On Sun, 2003-07-13 at 21:05, Colin Walters wrote:
> 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.
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.
--
Stephen Smalley <sds@epoch.ncsc.mil>
National Security Agency
--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-07-15 21:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-14 1:05 [patch] various fixes for libselinux Colin Walters
2003-07-15 21:07 ` Stephen Smalley
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.