From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751456AbdE0DYC (ORCPT ); Fri, 26 May 2017 23:24:02 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:34930 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751380AbdE0DUx (ORCPT ); Fri, 26 May 2017 23:20:53 -0400 Date: Fri, 26 May 2017 20:20:47 -0700 (PDT) From: Richard Narron X-X-Sender: comet.berkeley@joy.test To: Joe Perches cc: LKML Subject: Re: [PATCH v3 1/1] partitions/msdos: FreeBSD UFS2 file systems are not recognized In-Reply-To: <1495850058.9389.4.camel@perches.com> Message-ID: References: <1495809112.29207.30.camel@perches.com> <1495842124.9389.2.camel@perches.com> <1495850058.9389.4.camel@perches.com> User-Agent: Alpine 2.21 (LNX 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 26 May 2017, Joe Perches wrote: > (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: >>>> >>>>> [] >>>>>> 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. > Under the /block/partitions directory the c programs have about 13 uses of memcmp() and 6 uses of strcmp().