Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1233096 > unrolled thread

[PATCH 5/5] selinux: use sprintf return value

Started byRasmus Villemoes <linux@rasmusvillemoes.dk>
First post2015-09-26 00:40 +0200
Last post2015-09-30 18:50 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 5/5] selinux: use sprintf return value Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-09-26 00:40 +0200
    Re: [PATCH 5/5] selinux: use sprintf return value Rasmus Villemoes <linux@rasmusvillemoes.dk> - 2015-09-30 17:10 +0200
    Re: [PATCH 5/5] selinux: use sprintf return value Paul Moore <paul@paul-moore.com> - 2015-09-30 18:50 +0200

#1233096 — [PATCH 5/5] selinux: use sprintf return value

FromRasmus Villemoes <linux@rasmusvillemoes.dk>
Date2015-09-26 00:40 +0200
Subject[PATCH 5/5] selinux: use sprintf return value
Message-ID<qcJON-6x2-1@gated-at.bofh.it>
sprintf returns the number of characters printed (excluding '\0'), so
we can use that and avoid duplicating the length computation.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
 security/selinux/ss/services.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index aa2bdcb20848..ebb5eb3c318c 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1218,13 +1218,10 @@ static int context_struct_to_string(struct context *context, char **scontext, u3
 	/*
 	 * Copy the user name, role name and type name into the context.
 	 */
-	sprintf(scontextp, "%s:%s:%s",
+	scontextp += sprintf(scontextp, "%s:%s:%s",
 		sym_name(&policydb, SYM_USERS, context->user - 1),
 		sym_name(&policydb, SYM_ROLES, context->role - 1),
 		sym_name(&policydb, SYM_TYPES, context->type - 1));
-	scontextp += strlen(sym_name(&policydb, SYM_USERS, context->user - 1)) +
-		     1 + strlen(sym_name(&policydb, SYM_ROLES, context->role - 1)) +
-		     1 + strlen(sym_name(&policydb, SYM_TYPES, context->type - 1));
 
 	mls_sid_to_context(context, &scontextp);
 
-- 
2.1.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1236426

FromRasmus Villemoes <linux@rasmusvillemoes.dk>
Date2015-09-30 17:10 +0200
Message-ID<qerb4-9v-7@gated-at.bofh.it>
In reply to#1233096
On Tue, Sep 29 2015, Stephen Smalley <sds@tycho.nsa.gov> wrote:

> On 09/25/2015 06:34 PM, Rasmus Villemoes wrote:
>> sprintf returns the number of characters printed (excluding '\0'), so
>> we can use that and avoid duplicating the length computation.
>>
>> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
>
> Acked-by:  Stephen Smalley <sds@tycho.nsa.gov>

Thanks. I also like Joe's add-on suggestion (except I'd declare user,
role, type as const char*).

Rasmus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1236534

FromPaul Moore <paul@paul-moore.com>
Date2015-09-30 18:50 +0200
Message-ID<qesJQ-2eW-27@gated-at.bofh.it>
In reply to#1233096
On Saturday, September 26, 2015 12:34:19 AM Rasmus Villemoes wrote:
> sprintf returns the number of characters printed (excluding '\0'), so
> we can use that and avoid duplicating the length computation.
> 
> Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> ---
>  security/selinux/ss/services.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)

Applied, thank you.

I just pushed all five of your patches to the SELinux next branch so they 
should be included in the next linux-next release.

> diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
> index aa2bdcb20848..ebb5eb3c318c 100644
> --- a/security/selinux/ss/services.c
> +++ b/security/selinux/ss/services.c
> @@ -1218,13 +1218,10 @@ static int context_struct_to_string(struct context
> *context, char **scontext, u3 /*
>  	 * Copy the user name, role name and type name into the context.
>  	 */
> -	sprintf(scontextp, "%s:%s:%s",
> +	scontextp += sprintf(scontextp, "%s:%s:%s",
>  		sym_name(&policydb, SYM_USERS, context->user - 1),
>  		sym_name(&policydb, SYM_ROLES, context->role - 1),
>  		sym_name(&policydb, SYM_TYPES, context->type - 1));
> -	scontextp += strlen(sym_name(&policydb, SYM_USERS, context->user - 1)) +
> -		     1 + strlen(sym_name(&policydb, SYM_ROLES, context->role - 1)) +
> -		     1 + strlen(sym_name(&policydb, SYM_TYPES, context->type - 1));
> 
>  	mls_sid_to_context(context, &scontextp);

-- 
paul moore
www.paul-moore.com

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web