mirror of https://gitee.com/openkylin/libvirt.git
maint: don't leave garbage on early API exit
Several APIs clear out a user input buffer before attempting to populate it; but in a few cases we missed this memset if we detect a reason for an early exit. Note that these APIs check for non-NULL arguments, and exit early with an error message when NULL is passed in; which means that we must be careful to avoid a NULL deref in order to get to that error message. Also, we were inconsistent on the use of sizeof(virType) vs. sizeof(expression); the latter is more robust if we ever change the type of the expression (although such action is unlikely since these types are part of our public API). * src/libvirt.c (virDomainGetInfo, virDomainGetBlockInfo) (virStoragePoolGetInfo, virStorageVolGetInfo) (virDomainGetJobInfo, virDomainGetBlockJobInfo): Move memset before any returns. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
fe89b687a0
commit
c05aebfd65
|
@ -4144,11 +4144,12 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
|
||||||
|
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
|
if (info)
|
||||||
|
memset(info, 0, sizeof(*info));
|
||||||
|
|
||||||
virCheckDomainReturn(domain, -1);
|
virCheckDomainReturn(domain, -1);
|
||||||
virCheckNonNullArgGoto(info, error);
|
virCheckNonNullArgGoto(info, error);
|
||||||
|
|
||||||
memset(info, 0, sizeof(virDomainInfo));
|
|
||||||
|
|
||||||
conn = domain->conn;
|
conn = domain->conn;
|
||||||
|
|
||||||
if (conn->driver->domainGetInfo) {
|
if (conn->driver->domainGetInfo) {
|
||||||
|
@ -8449,12 +8450,13 @@ virDomainGetBlockInfo(virDomainPtr domain, const char *disk,
|
||||||
|
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
|
if (info)
|
||||||
|
memset(info, 0, sizeof(*info));
|
||||||
|
|
||||||
virCheckDomainReturn(domain, -1);
|
virCheckDomainReturn(domain, -1);
|
||||||
virCheckNonNullArgGoto(disk, error);
|
virCheckNonNullArgGoto(disk, error);
|
||||||
virCheckNonNullArgGoto(info, error);
|
virCheckNonNullArgGoto(info, error);
|
||||||
|
|
||||||
memset(info, 0, sizeof(virDomainBlockInfo));
|
|
||||||
|
|
||||||
conn = domain->conn;
|
conn = domain->conn;
|
||||||
|
|
||||||
if (conn->driver->domainGetBlockInfo) {
|
if (conn->driver->domainGetBlockInfo) {
|
||||||
|
@ -13082,11 +13084,12 @@ virStoragePoolGetInfo(virStoragePoolPtr pool,
|
||||||
|
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
|
if (info)
|
||||||
|
memset(info, 0, sizeof(*info));
|
||||||
|
|
||||||
virCheckStoragePoolReturn(pool, -1);
|
virCheckStoragePoolReturn(pool, -1);
|
||||||
virCheckNonNullArgGoto(info, error);
|
virCheckNonNullArgGoto(info, error);
|
||||||
|
|
||||||
memset(info, 0, sizeof(virStoragePoolInfo));
|
|
||||||
|
|
||||||
conn = pool->conn;
|
conn = pool->conn;
|
||||||
|
|
||||||
if (conn->storageDriver->storagePoolGetInfo) {
|
if (conn->storageDriver->storagePoolGetInfo) {
|
||||||
|
@ -13951,11 +13954,12 @@ virStorageVolGetInfo(virStorageVolPtr vol,
|
||||||
|
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
|
if (info)
|
||||||
|
memset(info, 0, sizeof(*info));
|
||||||
|
|
||||||
virCheckStorageVolReturn(vol, -1);
|
virCheckStorageVolReturn(vol, -1);
|
||||||
virCheckNonNullArgGoto(info, error);
|
virCheckNonNullArgGoto(info, error);
|
||||||
|
|
||||||
memset(info, 0, sizeof(virStorageVolInfo));
|
|
||||||
|
|
||||||
conn = vol->conn;
|
conn = vol->conn;
|
||||||
|
|
||||||
if (conn->storageDriver->storageVolGetInfo){
|
if (conn->storageDriver->storageVolGetInfo){
|
||||||
|
@ -17240,11 +17244,12 @@ virDomainGetJobInfo(virDomainPtr domain, virDomainJobInfoPtr info)
|
||||||
|
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
|
if (info)
|
||||||
|
memset(info, 0, sizeof(*info));
|
||||||
|
|
||||||
virCheckDomainReturn(domain, -1);
|
virCheckDomainReturn(domain, -1);
|
||||||
virCheckNonNullArgGoto(info, error);
|
virCheckNonNullArgGoto(info, error);
|
||||||
|
|
||||||
memset(info, 0, sizeof(virDomainJobInfo));
|
|
||||||
|
|
||||||
conn = domain->conn;
|
conn = domain->conn;
|
||||||
|
|
||||||
if (conn->driver->domainGetJobInfo) {
|
if (conn->driver->domainGetJobInfo) {
|
||||||
|
@ -19379,14 +19384,15 @@ virDomainGetBlockJobInfo(virDomainPtr dom, const char *disk,
|
||||||
|
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
|
if (info)
|
||||||
|
memset(info, 0, sizeof(*info));
|
||||||
|
|
||||||
virCheckDomainReturn(dom, -1);
|
virCheckDomainReturn(dom, -1);
|
||||||
conn = dom->conn;
|
conn = dom->conn;
|
||||||
|
|
||||||
virCheckNonNullArgGoto(disk, error);
|
virCheckNonNullArgGoto(disk, error);
|
||||||
virCheckNonNullArgGoto(info, error);
|
virCheckNonNullArgGoto(info, error);
|
||||||
|
|
||||||
memset(info, 0, sizeof(*info));
|
|
||||||
|
|
||||||
if (conn->driver->domainGetBlockJobInfo) {
|
if (conn->driver->domainGetBlockJobInfo) {
|
||||||
int ret;
|
int ret;
|
||||||
ret = conn->driver->domainGetBlockJobInfo(dom, disk, info, flags);
|
ret = conn->driver->domainGetBlockJobInfo(dom, disk, info, flags);
|
||||||
|
|
Loading…
Reference in New Issue