From: Joe Perches <joe@perches.com>
To: Richard Narron <comet.berkeley@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 1/1] partitions/msdos: FreeBSD UFS2 file systems are not recognized
Date: Fri, 26 May 2017 18:54:18 -0700 [thread overview]
Message-ID: <1495850058.9389.4.camel@perches.com> (raw)
In-Reply-To: <alpine.LNX.2.21.1705261737590.2924@joy.test>
(please keep replies on the list)
On Fri, 2017-05-26 at 18:33 -0700, Richard Narron wrote:
> On Fri, 26 May 2017, Joe Perches wrote:
> > On Fri, 2017-05-26 at 16:30 -0700, Richard Narron wrote:
> > > On Fri, 26 May 2017, Joe Perches wrote:
> > > > On Fri, 2017-05-26 at 03:48 -0700, Richard Narron wrote:
> > > > > The code in block/partitions/msdos.c recognizes FreeBSD, OpenBSD
> > > > > and NetBSD partitions and does a reasonable job picking out OpenBSD
> > > > > and NetBSD UFS subpartitions.
> > > > >
> > > > > But for FreeBSD the subpartitions are always "bad".
> > > > >
> > > > > Kernel: <bsd:bad subpartition - ignored
> > > >
> > > > []
> > > > > block/partitions/msdos.c | 2 ++
> > > >
> > > > []
> > > > > @@ -300,6 +300,8 @@ static void parse_bsd(struct parsed_part
> > > > > continue;
> > > > > bsd_start = le32_to_cpu(p->p_offset);
> > > > > bsd_size = le32_to_cpu(p->p_size);
> > > > > + if (memcmp(flavour, "bsd\0", 4) == 0)
> > > >
> > > > Weird code. Why not:
> > > >
> > > > if (strcmp(flavor, "bsd") == 0)
> > > >
> > >
> > > I instinctively trust the memcmp function as it seems more like
> > > assembly language to me and more straight forward and more reliable than
> > > strcmp.
> >
> > That really doesn't matter.
> >
> > Your code stores "bsd\0\0" and not just "bsd\0"
> >
>
> Thanks for looking at this code. I do appreciate it.
>
> How about saving a byte and doing this instead?
>
> if (memcmp(flavour, "bsd", 4) == 0)
>
> I do appreciate your input as coding style is important, but so too is
> reliability.
>
> I don't trust the string functions and probably never will.
>
> It is not surprising to me that things like SQL injection and any number of other
> C string exploits are very common.
>
> IBM gave up on the idea of marking memory to keep track of data length with the 1401 machines in the 1950's.
>
> But Digital Equipment kept the idea alive of using null characters for a
> long time. Sadly the C programming language copied this bad idea for
> strings.
Let's not argue the language.
Please use what's normal for the language as that is
readers of the code typically expect.
next prev parent reply other threads:[~2017-05-27 1:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-26 10:48 [PATCH v3 1/1] partitions/msdos: FreeBSD UFS2 file systems are not recognized Richard Narron
2017-05-26 13:23 ` Jens Axboe
2017-05-26 14:31 ` Joe Perches
2017-05-26 23:30 ` Richard Narron
2017-05-26 23:42 ` Joe Perches
[not found] ` <alpine.LNX.2.21.1705261737590.2924@joy.test>
2017-05-27 1:54 ` Joe Perches [this message]
2017-05-27 3:20 ` Richard Narron
2017-05-27 3:48 ` Joe Perches
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=1495850058.9389.4.camel@perches.com \
--to=joe@perches.com \
--cc=comet.berkeley@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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