From: "Jan Beulich" Subject: Re: [PATCH] hvmloader/smbios: Change strncpy to memcpy for anchor strings. Date: Tue, 24 Sep 2013 11:18:40 +0100 Message-ID: <5241832002000078000F5D3F@nat28.tlf.novell.com> References: <52417A0202000078000F5CD4@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VOPhD-0006id-0o for xen-devel@lists.xenproject.org; Tue, 24 Sep 2013 10:18:19 +0000 In-Reply-To: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Paul Durrant , Keir Fraser Cc: Andrew Cooper , xen-devel List-Id: xen-devel@lists.xenproject.org >>> On 24.09.13 at 12:11, Keir Fraser wrote: > On 24/09/2013 10:39, "Jan Beulich" wrote: > >>>> - strncpy(ep->anchor_string, "_SM_", 4); >>>> + memcpy(ep->anchor_string, "_SM_", sizeof(ep->anchor_string)); >>> >>> Why the change from 4 to sizeof(ep->anchor_string) here (and similar below)? >>> Setting the copy length based on the size of the destination rather than the >>> source seems like the wrong thing to do. >> >> One can argue either way here: >> - passing the destination's size guarantees no memory corruption >> - passing the source's size guarantees no uninitialized memory >> >> Since the structure fields involved here aren't going to change, >> either way is fine imo. > > As was the unadorned number 4, imo. Yes - I'm fine with both; I don't even favor one over the other. Jan