From owner-freebsd-audit Fri Aug 4 14:33:28 2000 Delivered-To: freebsd-audit@freebsd.org Received: from rover.village.org (rover.village.org [204.144.255.49]) by hub.freebsd.org (Postfix) with ESMTP id EA3E137BA3B; Fri, 4 Aug 2000 14:33:16 -0700 (PDT) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (harmony.village.org [10.0.0.6]) by rover.village.org (8.9.3/8.9.3) with ESMTP id PAA75422; Fri, 4 Aug 2000 15:33:15 -0600 (MDT) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (localhost.village.org [127.0.0.1]) by harmony.village.org (8.9.3/8.8.3) with ESMTP id PAA13109; Fri, 4 Aug 2000 15:33:07 -0600 (MDT) Message-Id: <200008042133.PAA13109@harmony.village.org> To: Kris Kennaway Subject: Re: ether_line() patch Cc: audit@FreeBSD.ORG In-reply-to: Your message of "Fri, 04 Aug 2000 14:27:59 PDT." References: Date: Fri, 04 Aug 2000 15:33:07 -0600 From: Warner Losh Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In message Kris Kennaway writes: : On Fri, 4 Aug 2000, Warner Losh wrote: : : > This is incorrect too. It should be buf[sizeof(buf) - 1] = '\0'; : > because the valid range of buf is [0..sizeof(buf) - 1]. You don't : > need the -1 on strncpy, but that's a style issue. The post conditions : > are identical with it or without it: : : Oops again :) : : This change was just intended to be the above style : issue/micro-optimization (until I noticed the real bug in the old code). : In this case sizeof(buf) - 1 should still be correctly optimized by the : compiler since it's a compile-time constant, right? Yes. Just pointing out that each optimization might have other, unintended effects. Usually, I do the following stylaistically: strncpy(dst, src, X); dst[X] = '\0'; where X is the size of the buffer minus 1. This goes to show how right Theo de Raadt was with his strlcpy API change :-). Getting this right is too tedious to be left to the user. Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message