From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751937AbcC3LKm (ORCPT ); Wed, 30 Mar 2016 07:10:42 -0400 Received: from mga03.intel.com ([134.134.136.65]:17696 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750749AbcC3LKk (ORCPT ); Wed, 30 Mar 2016 07:10:40 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,415,1455004800"; d="scan'208";a="75829121" Message-ID: <1459336290.5907.39.camel@linux.intel.com> Subject: Re: [PATCH v2 2/5] string_helpers: add kstrdup_quotable_cmdline From: Andy Shevchenko To: Kees Cook , James Morris Cc: "Serge E. Hallyn" , Andrew Morton , Kalle Valo , Mauro Carvalho Chehab , Joe Perches , Guenter Roeck , Jiri Slaby , Paul Moore , Stephen Smalley , Mimi Zohar , Casey Schaufler , Andreas Gruenbacher , Rasmus Villemoes , Ulf Hansson , Vitaly Kuznetsov , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 30 Mar 2016 14:11:30 +0300 In-Reply-To: <1459336039.5907.37.camel@linux.intel.com> References: <1459199662-16558-1-git-send-email-keescook@chromium.org> <1459199662-16558-3-git-send-email-keescook@chromium.org> <1459336039.5907.37.camel@linux.intel.com> Organization: Intel Finland Oy Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2016-03-30 at 14:07 +0300, Andy Shevchenko wrote: > On Mon, 2016-03-28 at 14:14 -0700, Kees Cook wrote: > > + res = get_cmdline(task, buffer, PAGE_SIZE - 1); > > + buffer[res] = '\0'; > > + > > + /* Collapse trailing NULLs. */ > > + for (; res > 0; res--) > > + if (buffer[res-1] != '\0') > > + break; > /* buffer[res] is '\0', so, predecrement is safe here */ > while (buffer[--res] == '\0') >  /* nothing */; > > ? > Oops, no, the following should be better while (--res >= 0 && buffer[res] == '\0') ; -- Andy Shevchenko Intel Finland Oy