esx_stream: Fix NULL dereferences

A wrong reordering caused "priv" to be derefenced before the NULL-check
in esxStreamSend and esxStreamRecvFlags.

Fixes: 12e19f172d
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Tim Wiederhake 2022-03-17 11:30:16 +01:00
parent 1dfd308843
commit 5e1da78967

View File

@ -198,8 +198,8 @@ esxStreamTransfer(esxStreamPrivate *priv, bool blocking)
static int static int
esxStreamSend(virStreamPtr stream, const char *data, size_t nbytes) esxStreamSend(virStreamPtr stream, const char *data, size_t nbytes)
{ {
int result = -1;
esxStreamPrivate *priv = stream->privateData; esxStreamPrivate *priv = stream->privateData;
VIR_LOCK_GUARD lock = virLockGuardLock(&priv->curl->lock);
if (nbytes == 0) if (nbytes == 0)
return 0; return 0;
@ -214,6 +214,7 @@ esxStreamSend(virStreamPtr stream, const char *data, size_t nbytes)
return -1; return -1;
} }
VIR_WITH_MUTEX_LOCK_GUARD(&priv->curl->lock) {
priv->buffer = (char *)data; priv->buffer = (char *)data;
priv->buffer_size = nbytes; priv->buffer_size = nbytes;
priv->buffer_used = nbytes; priv->buffer_used = nbytes;
@ -236,7 +237,10 @@ esxStreamSend(virStreamPtr stream, const char *data, size_t nbytes)
} while (priv->buffer_used > 0); } while (priv->buffer_used > 0);
} }
return priv->buffer_size - priv->buffer_used; result = priv->buffer_size - priv->buffer_used;
}
return result;
} }
static int static int
@ -245,8 +249,8 @@ esxStreamRecvFlags(virStreamPtr stream,
size_t nbytes, size_t nbytes,
unsigned int flags) unsigned int flags)
{ {
int result = -1;
esxStreamPrivate *priv = stream->privateData; esxStreamPrivate *priv = stream->privateData;
VIR_LOCK_GUARD lock = virLockGuardLock(&priv->curl->lock);
virCheckFlags(0, -1); virCheckFlags(0, -1);
@ -263,6 +267,7 @@ esxStreamRecvFlags(virStreamPtr stream,
return -1; return -1;
} }
VIR_WITH_MUTEX_LOCK_GUARD(&priv->curl->lock) {
priv->buffer = data; priv->buffer = data;
priv->buffer_size = nbytes; priv->buffer_size = nbytes;
priv->buffer_used = 0; priv->buffer_used = 0;
@ -296,7 +301,10 @@ esxStreamRecvFlags(virStreamPtr stream,
} while (priv->buffer_used < priv->buffer_size); } while (priv->buffer_used < priv->buffer_size);
} }
return priv->buffer_used; result = priv->buffer_used;
}
return result;
} }
static int static int