From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756823AbbA2Tlm (ORCPT ); Thu, 29 Jan 2015 14:41:42 -0500 Received: from [68.232.143.164] ([68.232.143.164]:12455 "EHLO esa2.cray.iphmx.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1754582AbbA2Tll (ORCPT ); Thu, 29 Jan 2015 14:41:41 -0500 X-IronPort-AV: E=Sophos;i="5.09,487,1418083200"; d="scan'208";a="199968" Message-ID: <54CA8CA7.2070403@cray.com> Date: Thu, 29 Jan 2015 13:40:23 -0600 From: Frank Zago User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Rickard Strandqvist , Oleg Drokin , Andreas Dilger CC: , Greg Kroah-Hartman , , Subject: Re: [HPDD-discuss] [PATCH] staging: lustre: include: lustre_update.h: Fix for possible null pointer dereference References: <1422557229-3484-1-git-send-email-rickard_strandqvist@spectrumdigital.se> In-Reply-To: <1422557229-3484-1-git-send-email-rickard_strandqvist@spectrumdigital.se> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/29/2015 12:47 PM, Rickard Strandqvist wrote: > Fix a possible null pointer dereference, there is > otherwise a risk of a possible null pointer dereference. > > This was found using a static code analysis program called cppcheck > > Signed-off-by: Rickard Strandqvist > --- > drivers/staging/lustre/lustre/include/lustre_update.h | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/staging/lustre/lustre/include/lustre_update.h b/drivers/staging/lustre/lustre/include/lustre_update.h > index 84defce..00e1361 100644 > --- a/drivers/staging/lustre/lustre/include/lustre_update.h > +++ b/drivers/staging/lustre/lustre/include/lustre_update.h > @@ -165,12 +165,14 @@ static inline int update_get_reply_buf(struct update_reply *reply, void **buf, > int result; > > ptr = update_get_buf_internal(reply, index, &size); > + > + LASSERT((ptr != NULL && size >= sizeof(int))); Now size is tested before result. So it could assert if result < 0, while the function would have returned before. > + > result = *(int *)ptr; > > if (result < 0) > return result; > > - LASSERT((ptr != NULL && size >= sizeof(int))); > *buf = ptr + sizeof(int); > return size - sizeof(int); > } >