From: Colin Walters <walters@verbum.org>
To: selinux@tycho.nsa.gov
Subject: [patch] various fixes for libselinux
Date: 13 Jul 2003 21:05:18 -0400 [thread overview]
Message-ID: <1058144717.4130.5.camel@columbia> (raw)
[-- 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;
next reply other threads:[~2003-07-14 1:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-14 1:05 Colin Walters [this message]
2003-07-15 21:07 ` [patch] various fixes for libselinux Stephen Smalley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1058144717.4130.5.camel@columbia \
--to=walters@verbum.org \
--cc=selinux@tycho.nsa.gov \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.