All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Smalley <sds@tycho.nsa.gov>
To: Nicolas Iooss <nicolas.iooss@m4x.org>
Cc: selinux@tycho.nsa.gov
Subject: Re: [PATCH 6/7] libsemanage: genhomedircon: drop ustr dependency
Date: Wed, 21 Dec 2016 10:42:32 -0500	[thread overview]
Message-ID: <1482334952.8511.18.camel@tycho.nsa.gov> (raw)
In-Reply-To: <ef9a8c06-7eb5-ff65-12e5-21b2e88ab645@m4x.org>

On Wed, 2016-12-21 at 16:15 +0100, Nicolas Iooss wrote:
> On 19/12/16 19:32, Stephen Smalley wrote:
> > 
> > On Mon, 2016-12-19 at 14:04 +0100, Nicolas Iooss wrote:
> > > 
> > > ustr library uses old (pre-C99) "extern inline" semantic. This
> > > makes
> > > it
> > > incompatible with recent versions of gcc and clang, which default
> > > to
> > > C99 standard. Distributions have shipped patched versions of this
> > > library to fix issues (e.g. Gentoo package uses this patch:
> > > https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-libs/ustr/file
> > > s/us
> > > tr-1.0.4-gcc_5-
> > > check.patch?id=7dea6f8820f36bf389e6315044bea7507553bed0
> > > ) but there is no upstream solution to make ustr compatible with
> > > C99
> > > standard.
> > > 
> > > The git tree of ustr (http://www.and.org/ustr/ustr.git) has not
> > > been
> > > updated since 2008 and the developer of this project did not
> > > reply to
> > > emails.
> > > 
> > > Therefore update genhomedircon implementation in order to no
> > > longer
> > > rely on ustr library.
> > > 
> > > Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
> > > ---
> > >  libsemanage/src/genhomedircon.c | 137 +++++++++++++++++++-------
> > > ----
> > > ----------
> > >  1 file changed, 66 insertions(+), 71 deletions(-)
> > > 
> > > diff --git a/libsemanage/src/genhomedircon.c
> > > b/libsemanage/src/genhomedircon.c
> > > index 5e9d7224a06e..4b7352c8648a 100644
> > > --- a/libsemanage/src/genhomedircon.c
> > > +++ b/libsemanage/src/genhomedircon.c
> > > @@ -239,46 +238,35 @@ static int fcontext_matches(const
> > > semanage_fcontext_t *fcontext, void *varg)
> > >  {
> > >  	const char *oexpr =
> > > semanage_fcontext_get_expr(fcontext);
> > >  	fc_match_handle_t *handp = varg;
> > > -	struct Ustr *expr;
> > > +	char *expr = NULL;
> > >  	regex_t re;
> > >  	int type, retval = -1;
> > > +	size_t len;
> > >  
> > >  	/* Only match ALL or DIR */
> > >  	type = semanage_fcontext_get_type(fcontext);
> > >  	if (type != SEMANAGE_FCONTEXT_ALL && type !=
> > > SEMANAGE_FCONTEXT_ALL)
> > >  		return 0;
> > >  
> > > -	/* Convert oexpr into a Ustr and anchor it at the
> > > beginning
> > > */
> > > -	expr = ustr_dup_cstr("^");
> > > -	if (expr == USTR_NULL)
> > > -		goto done;
> > > -	if (!ustr_add_cstr(&expr, oexpr))
> > > -		goto done;
> > > +	len = strlen(oexpr);
> > >  
> > >  	/* Strip off trailing ".+" or ".*" */
> > > -	if (ustr_cmp_suffix_cstr_eq(expr, ".+") ||
> > > -	    ustr_cmp_suffix_cstr_eq(expr, ".*")) {
> > > -		if (!ustr_del(&expr, 2))
> > > -			goto done;
> > > -	}
> > > +	if (len >= 2 && oexpr[len - 2] == '.' && strchr("+*",
> > > oexpr[len - 1]))
> > > +		len -= 2;
> > >  
> > >  	/* Strip off trailing "(/.*)?" */
> > > -	if (ustr_cmp_suffix_cstr_eq(expr, "(/.*)?")) {
> > > -		if (!ustr_del(&expr, 6))
> > > -			goto done;
> > > -	}
> > > +	if (len >= 6 && !strncmp(oexpr + len - 6, "(/.*)?", 6))
> > > +		len -= 2;
> > 
> > Should be len -= 6;
> > Maybe we should make this code less fragile, e.g. #define the
> > expressions and use sizeof(X)-1 for the lengths in the strncmp()
> > and -=
> > statements, wrap it all up with a macro.
> 
> Thanks for your review. I have modified my patches and will send a v2
> once I tested them.
> For the new macro in fcontext_matches(), here is the code I am
> testing:
> 
> 	/* Define a macro to strip a literal string from the end of
> oexpr */
> #define rstrip_oexpr_len(cstr, cstrlen) \
> 	do { \
> 		if (len >= cstrlen && !strncmp(oexpr + len - cstrlen,
> cstr, cstrlen)) \
> 			len -= cstrlen; \
> 	} while (0)
> #define rstrip_oexpr(cstr) rstrip_oexpr_len(cstr, sizeof(cstr) - 1)
> 
> 	rstrip_oexpr(".+");
> 	rstrip_oexpr(".*");
> 	rstrip_oexpr("(/.*)?");
> 	rstrip_oexpr("/");
> 
> #undef rstrip_oexpr_len
> #undef rstrip_oexpr
> 
> 
> What would you think of such an implementation?

LGTM

  reply	other threads:[~2016-12-21 15:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-19 13:03 [PATCH 0/7] Remove ustr library dependency Nicolas Iooss
2016-12-19 13:03 ` [PATCH 1/7] libsemanage/tests: make "make test" fail when a CUnit test fails Nicolas Iooss
2016-12-19 13:03 ` [PATCH 2/7] libsemanage/tests: make tests standalone Nicolas Iooss
2016-12-19 13:04 ` [PATCH 3/7] libsemanage/tests: test more cases of semanage_split*() Nicolas Iooss
2016-12-19 13:04 ` [PATCH 4/7] libsemanage: simplify string utilities functions Nicolas Iooss
2016-12-19 15:46   ` Stephen Smalley
2016-12-21 15:23     ` Nicolas Iooss
2016-12-19 13:04 ` [PATCH 5/7] libsemanage: add semanage_str_replace() utility function Nicolas Iooss
2016-12-19 18:02   ` Stephen Smalley
2016-12-19 13:04 ` [PATCH 6/7] libsemanage: genhomedircon: drop ustr dependency Nicolas Iooss
2016-12-19 18:32   ` Stephen Smalley
2016-12-21 15:15     ` Nicolas Iooss
2016-12-21 15:42       ` Stephen Smalley [this message]
2016-12-19 18:43   ` Stephen Smalley
2016-12-19 13:04 ` [PATCH 7/7] libsemanage: remove ustr library from Makefiles, README and pkg-config Nicolas Iooss

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=1482334952.8511.18.camel@tycho.nsa.gov \
    --to=sds@tycho.nsa.gov \
    --cc=nicolas.iooss@m4x.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.