gsocket: Fix potential multiplication overflow calculating timeout

socket->priv->timeout is only a guint, and the multiplication is
performed before it’s widened to gint64 to be stored in start_time
(thanks, C). This means any timeout of 50 days or more would overflow.
Fixing this bug makes me feel a real sense of self-worth.

Coverity ID: 1159478

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2017-04-03 11:56:43 +01:00
parent 0e0b5dff7c
commit 1f396fd7d6

View File

@ -3857,7 +3857,7 @@ g_socket_condition_timed_wait (GSocket *socket,
if (socket->priv->timeout && if (socket->priv->timeout &&
(timeout < 0 || socket->priv->timeout < timeout / G_USEC_PER_SEC)) (timeout < 0 || socket->priv->timeout < timeout / G_USEC_PER_SEC))
timeout = socket->priv->timeout * 1000; timeout = (gint64) socket->priv->timeout * 1000;
else if (timeout != -1) else if (timeout != -1)
timeout = timeout / 1000; timeout = timeout / 1000;