mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 22:16:16 +01:00
gdatainputstream: Handle stop_chars_len internally as gsize
Previously it was handled as a `gssize`, which meant that if the `stop_chars` string was longer than `G_MAXSSIZE` there would be an overflow. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Helps: #2319
This commit is contained in:
parent
81a454237d
commit
41d5eedad4
@ -856,7 +856,7 @@ static gssize
|
|||||||
scan_for_chars (GDataInputStream *stream,
|
scan_for_chars (GDataInputStream *stream,
|
||||||
gsize *checked_out,
|
gsize *checked_out,
|
||||||
const char *stop_chars,
|
const char *stop_chars,
|
||||||
gssize stop_chars_len)
|
gsize stop_chars_len)
|
||||||
{
|
{
|
||||||
GBufferedInputStream *bstream;
|
GBufferedInputStream *bstream;
|
||||||
const char *buffer;
|
const char *buffer;
|
||||||
@ -952,7 +952,7 @@ typedef struct
|
|||||||
gsize checked;
|
gsize checked;
|
||||||
|
|
||||||
gchar *stop_chars;
|
gchar *stop_chars;
|
||||||
gssize stop_chars_len;
|
gsize stop_chars_len;
|
||||||
gsize length;
|
gsize length;
|
||||||
} GDataInputStreamReadData;
|
} GDataInputStreamReadData;
|
||||||
|
|
||||||
@ -1078,12 +1078,17 @@ g_data_input_stream_read_async (GDataInputStream *stream,
|
|||||||
{
|
{
|
||||||
GDataInputStreamReadData *data;
|
GDataInputStreamReadData *data;
|
||||||
GTask *task;
|
GTask *task;
|
||||||
|
gsize stop_chars_len_unsigned;
|
||||||
|
|
||||||
data = g_slice_new0 (GDataInputStreamReadData);
|
data = g_slice_new0 (GDataInputStreamReadData);
|
||||||
if (stop_chars_len == -1)
|
|
||||||
stop_chars_len = strlen (stop_chars);
|
if (stop_chars_len < 0)
|
||||||
data->stop_chars = g_memdup (stop_chars, stop_chars_len);
|
stop_chars_len_unsigned = strlen (stop_chars);
|
||||||
data->stop_chars_len = stop_chars_len;
|
else
|
||||||
|
stop_chars_len_unsigned = (gsize) stop_chars_len;
|
||||||
|
|
||||||
|
data->stop_chars = g_memdup2 (stop_chars, stop_chars_len_unsigned);
|
||||||
|
data->stop_chars_len = stop_chars_len_unsigned;
|
||||||
data->last_saw_cr = FALSE;
|
data->last_saw_cr = FALSE;
|
||||||
|
|
||||||
task = g_task_new (stream, cancellable, callback, user_data);
|
task = g_task_new (stream, cancellable, callback, user_data);
|
||||||
@ -1338,17 +1343,20 @@ g_data_input_stream_read_upto (GDataInputStream *stream,
|
|||||||
gssize found_pos;
|
gssize found_pos;
|
||||||
gssize res;
|
gssize res;
|
||||||
char *data_until;
|
char *data_until;
|
||||||
|
gsize stop_chars_len_unsigned;
|
||||||
|
|
||||||
g_return_val_if_fail (G_IS_DATA_INPUT_STREAM (stream), NULL);
|
g_return_val_if_fail (G_IS_DATA_INPUT_STREAM (stream), NULL);
|
||||||
|
|
||||||
if (stop_chars_len < 0)
|
if (stop_chars_len < 0)
|
||||||
stop_chars_len = strlen (stop_chars);
|
stop_chars_len_unsigned = strlen (stop_chars);
|
||||||
|
else
|
||||||
|
stop_chars_len_unsigned = (gsize) stop_chars_len;
|
||||||
|
|
||||||
bstream = G_BUFFERED_INPUT_STREAM (stream);
|
bstream = G_BUFFERED_INPUT_STREAM (stream);
|
||||||
|
|
||||||
checked = 0;
|
checked = 0;
|
||||||
|
|
||||||
while ((found_pos = scan_for_chars (stream, &checked, stop_chars, stop_chars_len)) == -1)
|
while ((found_pos = scan_for_chars (stream, &checked, stop_chars, stop_chars_len_unsigned)) == -1)
|
||||||
{
|
{
|
||||||
if (g_buffered_input_stream_get_available (bstream) ==
|
if (g_buffered_input_stream_get_available (bstream) ==
|
||||||
g_buffered_input_stream_get_buffer_size (bstream))
|
g_buffered_input_stream_get_buffer_size (bstream))
|
||||||
|
Loading…
Reference in New Issue
Block a user