From: Luk Claes <luk@debian.org>
To: NeilBrown <neilb@suse.de>
Cc: Steve Dickson <SteveD@redhat.com>, linux-nfs@vger.kernel.org
Subject: Re: [PATCH] Do not segfault because of kernel version
Date: Sun, 03 Jul 2011 08:37:11 +0200 [thread overview]
Message-ID: <4E100E17.5000304@debian.org> (raw)
In-Reply-To: <20110703150421.2db09d94@notabene.brown>
On 07/03/2011 07:04 AM, NeilBrown wrote:
> On Sat, 2 Jul 2011 16:32:29 +0200 Luk Claes <luk@debian.org> wrote:
>
>> mount.nfs segfaults if kernel version number does not contain
>> at least 3 components delimited with a dot.
>>
>> Avoid this by matching up to three unsigned integers inialised
>> to zero, separated by dots.
>>
>> Signed-off-by: Luk Claes <luk@debian.org>
>> ---
>> utils/mount/version.h | 11 +++++------
>> 1 files changed, 5 insertions(+), 6 deletions(-)
>>
>> diff --git a/utils/mount/version.h b/utils/mount/version.h
>> index af61a6f..2642eab 100644
>> --- a/utils/mount/version.h
>> +++ b/utils/mount/version.h
>> @@ -23,8 +23,7 @@
>> #ifndef _NFS_UTILS_MOUNT_VERSION_H
>> #define _NFS_UTILS_MOUNT_VERSION_H
>>
>> -#include <stdlib.h>
>> -#include <string.h>
>> +#include <stdio.h>
>>
>> #include <sys/utsname.h>
>>
>> @@ -37,14 +36,14 @@ static inline unsigned int MAKE_VERSION(unsigned int p, unsigned int q,
>> static inline unsigned int linux_version_code(void)
>> {
>> struct utsname my_utsname;
>> - unsigned int p, q, r;
>> + unsigned int p, q = 0, r = 0;
>>
>> if (uname(&my_utsname))
>> return 0;
>>
>> - p = (unsigned int)atoi(strtok(my_utsname.release, "."));
>> - q = (unsigned int)atoi(strtok(NULL, "."));
>> - r = (unsigned int)atoi(strtok(NULL, "."));
>> + if (sscanf(my_utsname.release, "%u.%u.%u", &p, &q, &r) < 1)
>> + return 0;
>> +
>
> According to Linus, the error case should return a big number, not a small
> number.
> So if the version number is not recognised - e.g. it was written in Sanskrit
> rather than arabic numberals, it is assumed to be a future version, not a
> past version.
>
> https://lkml.org/lkml/2011/6/14/293
Ah, not a bad idea. In that case a parse error can be distinguished from
other errors. Would 'return -1' do the expected or will it give a
compiler warning/error we should avoid?
Cheers
Luk
next prev parent reply other threads:[~2011-07-03 6:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-02 14:32 [PATCH] Do not segfault because of kernel version Luk Claes
2011-07-03 5:04 ` NeilBrown
2011-07-03 6:37 ` Luk Claes [this message]
2011-07-03 13:02 ` Jim Rees
2011-07-03 13:10 ` Luk Claes
2011-07-03 13:26 ` Jim Rees
2011-07-03 13:28 ` Luk Claes
2011-07-03 14:11 ` Jim Rees
2011-07-04 16:28 ` Luk Claes
2011-07-04 19:00 ` Jim Rees
2011-07-05 5:42 ` Luk Claes
2011-07-05 5:42 ` Luk Claes
2011-07-12 14:42 ` Steve Dickson
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=4E100E17.5000304@debian.org \
--to=luk@debian.org \
--cc=SteveD@redhat.com \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.