Received: from eggs.gnu.org ([2001:4830:134:3::10]:34358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WooDJ-0007o0-2S for qemu-devel@nongnu.org; Mon, 26 May 2014 02:16:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WooDD-0005Je-8a for qemu-devel@nongnu.org; Mon, 26 May 2014 02:16:49 -0400 Received: from oxygen.pond.sub.org ([2a01:4f8:201:233:1::3]:46467) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WooDD-0005IG-1u for qemu-devel@nongnu.org; Mon, 26 May 2014 02:16:43 -0400 From: Markus Armbruster References: <1400844279-1685-1-git-send-email-armbru@redhat.com> <1400844279-1685-7-git-send-email-armbru@redhat.com> <537F8EF4.9000803@tls.msk.ru> <537F906E.4010101@msgid.tls.msk.ru> <537F910A.2070902@msgid.tls.msk.ru> Date: Mon, 26 May 2014 08:16:37 +0200 In-Reply-To: <537F910A.2070902@msgid.tls.msk.ru> (Michael Tokarev's message of "Fri, 23 May 2014 22:18:50 +0400") Message-ID: <87zji5awu2.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 6/7] libcacard/vcard_emul_nss: Assert vreaderOpt isn't null List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Michael Tokarev Cc: alevy@redhat.com, qemu-devel@nongnu.org Michael Tokarev writes: > 23.05.2014 22:16, Michael Tokarev =D0=BF=D0=B8=D1=88=D0=B5=D1=82: >> 23.05.2014 22:09, Michael Tokarev wrote: >>> 23.05.2014 15:24, Markus Armbruster wrote: >>>> It's not locally obvious, and Coverity can't see it either. >>>> >>>> Signed-off-by: Markus Armbruster >>>> Reviewed-by: Alon Levy >>>> --- >>>> libcacard/vcard_emul_nss.c | 1 + >>>> 1 file changed, 1 insertion(+) >>>> >>>> diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c >>>> index 2048917..4f55e44 100644 >>>> --- a/libcacard/vcard_emul_nss.c >>>> +++ b/libcacard/vcard_emul_nss.c >>>> @@ -1181,6 +1181,7 @@ vcard_emul_options(const char *args) >>>> vreaderOpt =3D g_renew(VirtualReaderOptions, opts->vr= eader, >>>> reader_count); >>>> } >>>> + assert(vreaderOpt); >>>> opts->vreader =3D vreaderOpt; >>>> vreaderOpt =3D &vreaderOpt[opts->vreader_count]; >>>> vreaderOpt->name =3D g_strndup(name, name_length); >>> >>> Shouldn't the assignment be moved up one line into the if {} >>> statement instead? >>=20 >> Actually it looks like this code is just buggy, it works for just >> one iteration. Because at this place, vreaderOpts will be non-NULL >> only if we expanded the array. If we didn't (we do that in >> READER_STEP increments), we'll be assigning NULL to opts->vreader, >> because vreaderOpt will _really_ be NULL here. You're right. When I saw the conditional realloc, I jumped to convince myself that it's always executed in the first loop iteration, but missed the fact that vreaderOpt is reset to null on *every* iteration. > So, the real fix is: > > 1) drop =3D NULL at declaration of vreaderOpt; > 2) do not mention vreaderOpt inside the if{} statement at > all, we don't need indirection there; > 3) drop this opts->vreader assignment > > and ofcourse do not add the assert as in the patch above ;) I'll review it. Thanks!