storage: fix crash caused by no check return before set close
authorLuyao Huang <lhuang@redhat.com>
Wed, 3 Dec 2014 15:01:32 +0000 (23:01 +0800)
committerEric Blake <eblake@redhat.com>
Mon, 22 Dec 2014 22:54:33 +0000 (15:54 -0700)
commitc89df3695b397d155ca15ac174c983ae9a77387e
tree02b5dffe40791e43ab644aadc9cf0d78a2e30303
parenta9638ae975a1c784d958e3fb2f0aab36b3ebddeb
storage: fix crash caused by no check return before set close

https://bugzilla.redhat.com/show_bug.cgi?id=1087104#c5

When trying to use an invalid offset to virStorageVolUpload(), libvirt
fails in virFDStreamOpenFileInternal(), although it seems libvirt does
not check the return in storageVolUpload(), and calls
virFDStreamSetInternalCloseCb() right after.  But stream doesn't have a
privateData (is NULL) yet, and the daemon crashes then.

0  0x00007f09429a9c10 in pthread_mutex_lock () from /lib64/libpthread.so.0
1  0x00007f094514dbf5 in virMutexLock (m=<optimized out>) at util/virthread.c:88
2  0x00007f09451cb211 in virFDStreamSetInternalCloseCb at fdstream.c:795
3  0x00007f092ff2c9eb in storageVolUpload at storage/storage_driver.c:2098
4  0x00007f09451f46e0 in virStorageVolUpload at libvirt.c:14000
5  0x00007f0945c78fa1 in remoteDispatchStorageVolUpload at remote_dispatch.h:14339
6  remoteDispatchStorageVolUploadHelper at remote_dispatch.h:14309
7  0x00007f094524a192 in virNetServerProgramDispatchCall at rpc/virnetserverprogram.c:437

Signed-off-by: Luyao Huang <lhuang@redhat.com>
(cherry picked from commit 87b9437f8951f9d24f9a85c6bbfff0e54df8c984)
src/storage/storage_driver.c