From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935501AbbI2SSI (ORCPT ); Tue, 29 Sep 2015 14:18:08 -0400 Received: from emvm-gh1-uea09.nsa.gov ([63.239.67.10]:64345 "EHLO emvm-gh1-uea09.nsa.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935330AbbI2SR7 (ORCPT ); Tue, 29 Sep 2015 14:17:59 -0400 X-TM-IMSS-Message-ID: <3322933600004758@nsa.gov> Subject: Re: [PATCH 5/5] selinux: use sprintf return value To: Rasmus Villemoes , Paul Moore , Eric Paris , James Morris , "Serge E. Hallyn" References: <1443220459-11042-1-git-send-email-linux@rasmusvillemoes.dk> <1443220459-11042-6-git-send-email-linux@rasmusvillemoes.dk> Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, selinux@tycho.nsa.gov From: Stephen Smalley Organization: National Security Agency Message-ID: <560AD5AF.4070400@tycho.nsa.gov> Date: Tue, 29 Sep 2015 14:17:19 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <1443220459-11042-6-git-send-email-linux@rasmusvillemoes.dk> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Acked-by: Stephen Smalley > --- > 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); > >