Re: [RFC PATCH] SELinux: Cleanup the secid/secctx conversion functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2008-02-29 at 09:13 -0500, Stephen Smalley wrote:
> On Fri, 2008-02-29 at 08:54 -0500, Stephen Smalley wrote:
> > The snippet below looks like a step backward rather than an improvement
> > - single sprintf replaced by series of strcat calls.  That can't be more
> > efficient.
> 
> Hmm...well, maybe I'm wrong (after looking at the implementations).
> Pity that Linux doesn't have stpcpy (as in glibc) - that is much nicer
> than a series of strcat's since it returns the end pointer and doesn't
> require finding the end of string each time.

 Note that you can do (only slightly abusing the interface):

	ctx = *scontext;

	ctx += strlcpy(ctx, policydb.p_user_val_to_name[context->user - 1], -1);
	ctx += strlcpy(ctx, ":", -1);
	ctx += strlcpy(ctx, policydb.p_role_val_to_name[context->role - 1], -1);
	ctx += strlcpy(ctx, ":", -1);
	ctx += strlcpy(ctx, policydb.p_type_val_to_name[context->type - 1], -1);

...which is basically a memcpy() with a simple if test.

> > > -	*scontextp = 0;
> > > +	ctx = *scontext;
> > > +	strcpy(ctx, policydb.p_user_val_to_name[context->user - 1]);
> > > +	strcat(ctx, ":");
> > > +	strcat(ctx, policydb.p_role_val_to_name[context->role - 1]);
> > > +	strcat(ctx, ":");
> > > +	strcat(ctx, policydb.p_type_val_to_name[context->type - 1]);
> > 
-- 
James Antill <james.antill@xxxxxxxxxx>
Red Hat

Attachment: signature.asc
Description: This is a digitally signed message part


[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux