Another fix on g_socket_send_message()

We forgot to take into account the case where num_vectors is '-1'.
This commit is contained in:
Emmanuel Fleury 2021-01-13 13:23:40 +01:00
parent 5f11206237
commit b6f7e4678b

View File

@ -4784,7 +4784,9 @@ g_socket_send_message (GSocket *socket,
gsize bytes_written = 0;
gsize vectors_size = 0;
for (gsize i = 0; i < num_vectors; i++)
if (num_vectors != -1)
{
for (gint i = 0; i < num_vectors; i++)
{
/* No wrap-around for vectors_size */
if (vectors_size > vectors_size + vectors[i].size)
@ -4797,6 +4799,23 @@ g_socket_send_message (GSocket *socket,
vectors_size += vectors[i].size;
}
}
else
{
for (gsize i = 0; vectors[i].buffer != NULL; i++)
{
/* No wrap-around for vectors_size */
if (vectors_size > vectors_size + vectors[i].size)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
_("Unable to send message: %s"),
_("Message vectors too large"));
return -1;
}
vectors_size += vectors[i].size;
}
}
/* Check if vector's buffers are too big for gssize */
if (vectors_size > G_MAXSSIZE)