All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ustr cleanups (policyrep branch)
@ 2007-10-01  6:46 James Antill
  2007-10-01 17:35 ` Todd Miller
  2007-10-05 14:19 ` Stephen Smalley
  0 siblings, 2 replies; 4+ messages in thread
From: James Antill @ 2007-10-01  6:46 UTC (permalink / raw)
  To: selinux


[-- Attachment #1.1: Type: text/plain, Size: 640 bytes --]


 Here are two cleanups for ustr usage within libsemanage on the
policyrep branch.

 The first is a corner case where you have two or more replacements in
the "replace_all" function of genhomedircon, previously one of those
multiple replacements (in theory) could fail due to malloc() returning
NULL and that would be missed. The fix probably makes the free test more
readable too.

 The second is that semanage_is_prefix() was previously defined by
calling ustr functions (inefficiently, even), and so had to allocate a
ustr to do it's work ... the fix just calls strncmp() directly.

-- 
James Antill <jantill@redhat.com>

[-- Attachment #1.2: selinux-semanage-policyrep-ustr-cleanups.patch --]
[-- Type: text/x-patch, Size: 1780 bytes --]

diff --git a/branches/policyrep/libsemanage/src/genhomedircon.c b/branches/policyrep/libsemanage/src/genhomedircon.c
index 68dedc8..f4cc16b 100644
--- a/branches/policyrep/libsemanage/src/genhomedircon.c
+++ b/branches/policyrep/libsemanage/src/genhomedircon.c
@@ -322,7 +322,7 @@ static semanage_list_t *make_template(genhomedircon_settings_t * s,
 static Ustr *replace_all(const char *str, const replacement_pair_t * repl)
 {
 	Ustr *retval = USTR_NULL;
-	int i, num_replaced = 0;
+	int i;
 
 	if (!str || !repl)
 		goto done;
@@ -330,10 +330,10 @@ static Ustr *replace_all(const char *str, const replacement_pair_t * repl)
 		goto done;
 
 	for (i = 0; repl[i].search_for; i++) {
-		num_replaced += ustr_replace_cstr(&retval, repl[i].search_for,
-						  repl[i].replace_with, 0);
+		ustr_replace_cstr(&retval, repl[i].search_for,
+				  repl[i].replace_with, 0);
 	}
-	if (!num_replaced)
+	if (ustr_enomem(retval))
 		ustr_sc_free(&retval);
 
       done:
diff --git a/branches/policyrep/libsemanage/src/utilities.c b/branches/policyrep/libsemanage/src/utilities.c
index 6a997e9..349a4be 100644
--- a/branches/policyrep/libsemanage/src/utilities.c
+++ b/branches/policyrep/libsemanage/src/utilities.c
@@ -60,22 +60,14 @@ char *semanage_findval(char *file, char *var, char *delim)
 
 int semanage_is_prefix(const char *str, const char *prefix)
 {
-	int retval;
-	Ustr *ustr = USTR_NULL;
-
 	if (!str) {
 		return FALSE;
 	}
 	if (!prefix) {
 		return TRUE;
 	}
-	if (!(ustr = ustr_dup_cstr(str))) {
-		return FALSE;
-	}
-	retval = (ustr_srch_cstr_fwd(ustr, 0, prefix) == 1);
-	ustr_sc_free(&ustr);
 
-	return retval;
+	return strncmp(str, prefix, strlen(prefix)) == 0;
 }
 
 char *semanage_split_on_space(const char *str)

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-10-05 14:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-01  6:46 [PATCH] ustr cleanups (policyrep branch) James Antill
2007-10-01 17:35 ` Todd Miller
2007-10-01 18:40   ` James Antill
2007-10-05 14:19 ` 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.