From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033299AbdE0ByZ (ORCPT ); Fri, 26 May 2017 21:54:25 -0400 Received: from smtprelay0031.hostedemail.com ([216.40.44.31]:55323 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S937451AbdE0ByW (ORCPT ); Fri, 26 May 2017 21:54:22 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::,RULES_HIT:41:355:379:541:599:960:965:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2553:2559:2562:2689:2693:2828:2898:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:4385:4390:4395:4605:5007:6119:7875:7904:7974:9010:10004:10400:10848:11232:11658:11914:12296:12740:12760:12895:13255:13439:14096:14097:14659:14721:21080:21324:21325:21451:21627:30012:30034:30054:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: car42_8b34f9f02c2a X-Filterd-Recvd-Size: 3181 Message-ID: <1495850058.9389.4.camel@perches.com> Subject: Re: [PATCH v3 1/1] partitions/msdos: FreeBSD UFS2 file systems are not recognized From: Joe Perches To: Richard Narron Cc: LKML Date: Fri, 26 May 2017 18:54:18 -0700 In-Reply-To: References: <1495809112.29207.30.camel@perches.com> <1495842124.9389.2.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org (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.