From: James Antill <jantill@redhat.com>
To: selinux@tycho.nsa.gov
Subject: [PATCH] ustr cleanups (policyrep branch)
Date: Mon, 01 Oct 2007 02:46:36 -0400 [thread overview]
Message-ID: <1191221196.29631.44.camel@code.and.org> (raw)
[-- 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 --]
next reply other threads:[~2007-10-01 6:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-01 6:46 James Antill [this message]
2007-10-01 17:35 ` [PATCH] ustr cleanups (policyrep branch) Todd Miller
2007-10-01 18:40 ` James Antill
2007-10-05 14:19 ` 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=1191221196.29631.44.camel@code.and.org \
--to=jantill@redhat.com \
--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.