From: "Jan Beulich" Subject: Hazardous memset/memcpy idiom (was Re: [PATCH] x86: fix null pointer dereference in intel_get_extended_msrs()) Date: Wed, 27 Feb 2013 08:50:35 +0000 Message-ID: <512DD6EB02000078000C159C@nat28.tlf.novell.com> References: <1361598228-25041-1-git-send-email-xi@mit.edu> <20780.60434.402629.740920@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20780.60434.402629.740920@mariner.uk.xensource.com> 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: Ian Jackson , Stefano Stabellini , Keir Fraser , "Tim(Xen.org)" Cc: Xi Wang , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org >>> On 26.02.13 at 18:08, Ian Jackson wrote: > Xi Wang writes ("[Xen-devel] [PATCH] x86: fix null pointer dereference in > intel_get_extended_msrs()"): >> `memset(&mc_ext, 0, ...)' leads to a buffer overflow and a subsequent >> null pointer dereference. Replace `&mc_ext' with `mc_ext'. > > Really I think we shouldn't be writing out these kind of memsets. > They're too error-prone. We should have a macro, perhaps like this: > > #define FILLZERO(object) memset(&(object), 0, sizeof(object)) > > Likewise a copy macro. Unfortunately that wouldn't be usable in all cases (arrays passed to functions), and hence I'm not really confident this would be a good move. But yes, I considered what you suggest a number of times already, but dropped the idea each time because of its lack of general applicability. I'm afraid we just have to live with the bad side effects of the power C provides. Jan