public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
Cc: Oleg Drokin <oleg.drokin@intel.com>,
	Andreas Dilger <andreas.dilger@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Julia Lawall <Julia.Lawall@lip6.fr>,
	Greg Donald <gdonald@gmail.com>,
	"John L. Hammond" <john.hammond@intel.com>,
	Andriy Skulysh <Andriy_Skulysh@xyratex.com>,
	Fabian Frederick <fabf@skynet.be>,
	James Simmons <uja.ornl@gmail.com>,
	HPDD-discuss@ml01.01.org, devel@driverdev.osuosl.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c:  Fix for possible null pointer dereference
Date: Sun, 14 Dec 2014 17:51:37 -0800	[thread overview]
Message-ID: <1418608297.2674.4.camel@perches.com> (raw)
In-Reply-To: <1418597547-25086-1-git-send-email-rickard_strandqvist@spectrumdigital.se>

On Sun, 2014-12-14 at 23:52 +0100, Rickard Strandqvist wrote:
> There is otherwise a risk of a possible null pointer dereference.
> 
> Was largely found by using a static code analysis program called cppcheck.

Perhaps the tool could use a little work.
It's not possible for end to be NULL no?

unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
{
	unsigned long long result;
	unsigned int rv;

	cp = _parse_integer_fixup_radix(cp, &base);
	rv = _parse_integer(cp, base, &result);
	/* FIXME */
	cp += (rv & ~KSTRTOX_OVERFLOW);

	if (endp)
		*endp = (char *)cp;

	return result;
}
EXPORT_SYMBOL(simple_strtoull);


> diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
[]

Above this:

	whole = simple_strtoull(pbuf, &end, 10);

> +++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
> @@ -1897,17 +1897,19 @@ int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
>  	}
>  
>  	units = 1;
> -	switch (*end) {
> -	case 'p': case 'P':
> -		units <<= 10;
> -	case 't': case 'T':
> -		units <<= 10;
> -	case 'g': case 'G':
> -		units <<= 10;
> -	case 'm': case 'M':
> -		units <<= 10;
> -	case 'k': case 'K':
> -		units <<= 10;
> +	if (end) {
> +		switch (*end) {
> +		case 'p': case 'P':
> +			units <<= 10;
> +		case 't': case 'T':
> +			units <<= 10;
> +		case 'g': case 'G':
> +			units <<= 10;
> +		case 'm': case 'M':
> +			units <<= 10;
> +		case 'k': case 'K':
> +			units <<= 10;
> +		}

The only thing I might do is

	switch (tolower(*end)) {

and remove the second case entry for each line


  reply	other threads:[~2014-12-15  1:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-14 22:52 [PATCH] staging: lustre: lustre: obdclass: lprocfs_status.c: Fix for possible null pointer dereference Rickard Strandqvist
2014-12-15  1:51 ` Joe Perches [this message]
2014-12-15 22:23   ` Rickard Strandqvist
2014-12-15 23:53     ` Joe Perches
2014-12-16  3:08       ` [HPDD-discuss] " Patrick Farrell
2014-12-16  9:27     ` Dan Carpenter
2014-12-16  4:40 ` Chris Rorvick
  -- strict thread matches above, loose matches on Subject: below --
2014-12-14 22:36 Rickard Strandqvist
2014-12-14 22:39 ` Greg Kroah-Hartman
2014-12-14 22:43   ` Rickard Strandqvist

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1418608297.2674.4.camel@perches.com \
    --to=joe@perches.com \
    --cc=Andriy_Skulysh@xyratex.com \
    --cc=HPDD-discuss@ml01.01.org \
    --cc=Julia.Lawall@lip6.fr \
    --cc=andreas.dilger@intel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=fabf@skynet.be \
    --cc=gdonald@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=john.hammond@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg.drokin@intel.com \
    --cc=rickard_strandqvist@spectrumdigital.se \
    --cc=uja.ornl@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox