Received: from eggs.gnu.org ([2001:4830:134:3::10]:33325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YrovS-0006TL-5h for qemu-devel@nongnu.org; Mon, 11 May 2015 10:43:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YrovM-0003kl-HH for qemu-devel@nongnu.org; Mon, 11 May 2015 10:43:22 -0400 Date: Mon, 11 May 2015 15:43:09 +0100 From: Stefan Hajnoczi Message-ID: <20150511144309.GG16270@stefanha-thinkpad.redhat.com> References: <1430794275-1316-1-git-send-email-famz@redhat.com> <1430794275-1316-3-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="5UGlQXeG3ziZS81+" Content-Disposition: inline In-Reply-To: <1430794275-1316-3-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v5 2/3] block: Fix NULL deference for unaligned write if qiov is NULL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: pbonzini@redhat.com, Stefan Hajnoczi , qemu-devel@nongnu.org, qemu-block@nongnu.org, qemu-stable@nongnu.org --5UGlQXeG3ziZS81+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, May 05, 2015 at 10:51:14AM +0800, Fam Zheng wrote: This function is complex. I had to draw a diagram to remember the relationships between the variables. It would be nice to split it if that can be done in a way that makes the code nicer. > @@ -1236,13 +1238,39 @@ static int coroutine_fn bdrv_co_do_pwritev(BlockD= riverState *bs, > } > BLKDBG_EVENT(bs, BLKDBG_PWRITEV_RMW_AFTER_HEAD); > =20 > - qemu_iovec_init(&local_qiov, qiov->niov + 2); > - qemu_iovec_add(&local_qiov, head_buf, offset & (align - 1)); > - qemu_iovec_concat(&local_qiov, qiov, 0, qiov->size); > - use_local_qiov =3D true; > + if (qiov) { > + qemu_iovec_init(&local_qiov, qiov ? qiov->niov + 2 : 1); Should be: qemu_iovec_init(&local_qiov, qiov->niov + 2); since we know qiov !=3D NULL here. > @@ -1270,21 +1298,39 @@ static int coroutine_fn bdrv_co_do_pwritev(BlockD= riverState *bs, > } > BLKDBG_EVENT(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL); > =20 > - if (!use_local_qiov) { > - qemu_iovec_init(&local_qiov, qiov->niov + 1); > - qemu_iovec_concat(&local_qiov, qiov, 0, qiov->size); > - use_local_qiov =3D true; > + if (qiov) { > + if (!use_local_qiov) { > + qemu_iovec_init(&local_qiov, qiov->niov + 1); > + qemu_iovec_concat(&local_qiov, qiov, 0, qiov->size); > + use_local_qiov =3D true; > + } > + > + tail_bytes =3D (offset + bytes) & (align - 1); > + qemu_iovec_add(&local_qiov, tail_buf + tail_bytes, > + align - tail_bytes); > + > + bytes =3D ROUND_UP(bytes, align); > + } else { > + assert((offset & (align - 1)) =3D=3D 0); > + assert(bytes < align); > + > + memset(tail_buf, 0, bytes & (align - 1)); Since assert(bytes < align) is above, the following is clearer: memset(tail_buf, 0, bytes) --5UGlQXeG3ziZS81+ Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVUL/9AAoJEJykq7OBq3PIHscH/ieSl434xXZez9QaNM4TrN5S LFKBhtGpd1IH2kP/xl9EZEiFBtxIAVW2hhqdhxbJeu8ibPUULgR+8DWzTci7mAVI RUIf5aPlv4p0K0ZfnQk83/OfkSQ+8vxc7o6quH7E8C1vlPSHR/6Ns7TpBDuxWjYQ fDeAJc4fmfvFMPIgb3WOQicVL0M6QtENH/leOCAbumhSzLWC0npT4R8wqSGKrP2Q dql1MvRloY3TOf7FlbdYanEObQRjedtTgUmqt1i3DJyViho+kIe3i5Xatc5/ikZs RwP1H/3h3VA4acr7RCAI4S5fIFMnZCSBPsvsR/0UQxeAiTyjbrFoNk7dJytw34g= =cEep -----END PGP SIGNATURE----- --5UGlQXeG3ziZS81+--