From: Ian Jackson Subject: Re: [PATCH 10/22] libelf: check nul-terminated strings properly Date: Tue, 11 Jun 2013 16:17:15 +0100 Message-ID: <20919.16251.715642.107462@mariner.uk.xensource.com> References: <1370629642-6990-1-git-send-email-ian.jackson@eu.citrix.com> <1370629642-6990-11-git-send-email-ian.jackson@eu.citrix.com> <51B65E9D.3030303@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <51B65E9D.3030303@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: "xen-devel@lists.xensource.com" , "mattjd@gmail.com" , "security@xen.org" List-Id: xen-devel@lists.xenproject.org Andrew Cooper writes ("Re: [PATCH 10/22] libelf: check nul-terminated strings properly"): > On 07/06/13 19:27, Ian Jackson wrote: > > @@ -103,10 +103,13 @@ static int print_notes(struct elf_binary *elf, ELF_HANDLE_DECL(elf_note) start, > > { > > ELF_HANDLE_DECL(elf_note) note; > > int notes_found = 0; > > + const char *this_note_name; > > > > for ( note = start; ELF_HANDLE_PTRVAL(note) < ELF_HANDLE_PTRVAL(end); note = elf_note_next(elf, note) ) > > { > > - if (0 != strcmp(elf_note_name(elf, note), "Xen")) > > + this_note_name = elf_note_name(elf, note); > > + if (NULL == this_note_name || > > + 0 != strcmp(this_note_name, "Xen")) > > continue; > > Consistency? > > At various places in this patch, you differ between a single if > statement and two if statements to do this new extra checking for NULL. I will change the version in readnotes.c to use two statements. > The most concise would be > > if ( !ptr || !strcmp(ptr, "Xen") ) > > but it could certainly be argued that that is perhaps too concise. I would certainly normally write it that way but I am following the existing style in readnotes.c, which seems to have been written by someone who might as well prefer if (0 != (0 != (0 != some_boolean_expression ))) Ian.