All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Gyurdiev <ivg2@cornell.edu>
To: selinux@tycho.nsa.gov
Cc: Stephen Smalley <sds@tycho.nsa.gov>
Subject: [ SEPOL ] [ SEMANAGE 2] Fix spec for sepol_context_to_string
Date: Wed, 02 Nov 2005 02:19:35 -0500	[thread overview]
Message-ID: <43686887.7080001@cornell.edu> (raw)

[-- Attachment #1: Type: text/plain, Size: 106 bytes --]

Do not mix exit status with return value - use a parameter instead, like 
it's done for everything else.


[-- Attachment #2: libsepol.libsemanage.context_to_string.diff --]
[-- Type: text/x-patch, Size: 5003 bytes --]

diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/include/semanage/context_record.h new/libsemanage/include/semanage/context_record.h
--- old/libsemanage/include/semanage/context_record.h	2005-10-31 11:09:39.000000000 -0500
+++ new/libsemanage/include/semanage/context_record.h	2005-11-02 02:13:39.000000000 -0500
@@ -61,8 +61,9 @@ extern int semanage_context_from_string(
 	const char* str, 
 	semanage_context_t** con);
 
-extern char* semanage_context_to_string(
+extern int semanage_context_to_string(
 	semanage_handle_t* handle,
-	semanage_context_t* con);
+	semanage_context_t* con,
+	char** str_ptr);
 
 #endif 
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/context_record.c new/libsemanage/src/context_record.c
--- old/libsemanage/src/context_record.c	2005-10-31 11:09:39.000000000 -0500
+++ new/libsemanage/src/context_record.c	2005-11-02 02:11:36.000000000 -0500
@@ -88,9 +88,10 @@ int semanage_context_from_string(
 	return sepol_context_from_string(handle->sepolh, str, con);
 }
 
-char* semanage_context_to_string(
+int semanage_context_to_string(
 	semanage_handle_t* handle,
-	semanage_context_t* con) {
+	semanage_context_t* con,
+	char** str_ptr) {
 
-	return sepol_context_to_string(handle->sepolh, con);
+	return sepol_context_to_string(handle->sepolh, con, str_ptr);
 }
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/interfaces_file.c new/libsemanage/src/interfaces_file.c
--- old/libsemanage/src/interfaces_file.c	2005-11-02 02:04:33.000000000 -0500
+++ new/libsemanage/src/interfaces_file.c	2005-11-02 02:17:15.000000000 -0500
@@ -32,16 +32,14 @@ static int iface_print(
 	if (fprintf(str, "netifcon %s ", name) < 0)
 		goto err;
 
-	con_str = semanage_context_to_string(handle, ifcon);
-	if (!con_str)
+	if (semanage_context_to_string(handle, ifcon, &con_str) < 0)
 		goto err;
 	if (fprintf(str, "%s", con_str) < 0)
 		goto err;
 	free(con_str);
 	con_str = NULL;
 
-	con_str = semanage_context_to_string(handle, msgcon);
-	if (!con_str)
+	if (semanage_context_to_string(handle, msgcon, &con_str) < 0)
 		goto err;
 	if (fprintf(str, "%s\n", con_str) < 0)
 		goto err;
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/ports_file.c new/libsemanage/src/ports_file.c
--- old/libsemanage/src/ports_file.c	2005-11-02 02:04:33.000000000 -0500
+++ new/libsemanage/src/ports_file.c	2005-11-02 02:17:30.000000000 -0500
@@ -28,6 +28,7 @@ static int port_print(
 	int low = semanage_port_get_low(port);
 	int high = semanage_port_get_high(port);
 	const char* proto = semanage_port_get_proto_str(port);
+	semanage_context_t* con = semanage_port_get_con(port);
 
 	if (fprintf(str, "portcon %s ", proto) < 0)
 		goto err;
@@ -40,10 +41,8 @@ static int port_print(
 			goto err;
 	}
 
-	con_str = semanage_context_to_string(handle, semanage_port_get_con(port));
-	if (!con_str)
+	if (semanage_context_to_string(handle, con, &con_str) < 0)
 		goto err;
-
 	if (fprintf(str, "%s\n", con_str) < 0)
 		goto err;
 
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsepol/include/sepol/context_record.h new/libsepol/include/sepol/context_record.h
--- old/libsepol/include/sepol/context_record.h	2005-10-31 11:09:39.000000000 -0500
+++ new/libsepol/include/sepol/context_record.h	2005-11-02 02:10:35.000000000 -0500
@@ -64,8 +64,9 @@ extern int sepol_context_from_string(
 	const char* str, 
 	sepol_context_t** con);
 
-extern char* sepol_context_to_string(
+extern int sepol_context_to_string(
 	sepol_handle_t* handle,
-	sepol_context_t* con);
+	sepol_context_t* con,
+	char** str_ptr);
 
 #endif 
diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsepol/src/context_record.c new/libsepol/src/context_record.c
--- old/libsepol/src/context_record.c	2005-10-31 11:09:39.000000000 -0500
+++ new/libsepol/src/context_record.c	2005-11-02 02:14:07.000000000 -0500
@@ -246,21 +246,20 @@ int sepol_context_from_string(
 	return STATUS_ERR;
 }
 
-char* sepol_context_to_string(
+int sepol_context_to_string(
 	sepol_handle_t* handle,
-	sepol_context_t* con) {
+	sepol_context_t* con,
+	char** str_ptr) {
 
+	int rc;
 	const int user_sz = strlen(con->user);
 	const int role_sz = strlen(con->role);
 	const int type_sz = strlen(con->type);
 	const int mls_sz = (con->mls)? strlen(con->mls): 0;	
-
 	const int total_sz = user_sz + role_sz + type_sz + 
 		mls_sz + ((con->mls)? 3:2);
 
-	char* str = malloc(total_sz + 1);
-	int rc;
-
+	char* str = (char*) malloc(total_sz + 1);
 	if (!str)
 		goto omem;
 	
@@ -281,14 +280,14 @@ char* sepol_context_to_string(
 		}
 	}
 
-	return str; 
+	*str_ptr = str;
+	return STATUS_SUCCESS; 
 
 	omem:
 	ERR(handle, "out of memory");
 
 	err:
 	ERR(handle, "could not convert context to string");
-	if (str)
-		free(str);
-	return NULL;
+	free(str);
+	return STATUS_ERR;
 }

                 reply	other threads:[~2005-11-02  7:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=43686887.7080001@cornell.edu \
    --to=ivg2@cornell.edu \
    --cc=sds@tycho.nsa.gov \
    --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.