mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 06:26:15 +01:00
gdatainputstream: Fix length return value on UTF-8 validation failure
The method was correctly returning an error from `g_data_input_stream_read_line_utf8()` if the line contained invalid UTF-8, but it wasn’t correctly setting the returned line length to 0. This could have caused problems if callers were basing subsequent logic on the length and not the return value nullness or `GError`. Signed-off-by: Philip Withnall <pwithnall@gnome.org> oss-fuzz#372819437
This commit is contained in:
parent
38000eb9a0
commit
048a0f73e9
@ -840,7 +840,11 @@ g_data_input_stream_read_line_utf8 (GDataInputStream *stream,
|
||||
g_set_error_literal (error, G_CONVERT_ERROR,
|
||||
G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
|
||||
_("Invalid byte sequence in conversion input"));
|
||||
|
||||
if (length != NULL)
|
||||
*length = 0;
|
||||
g_free (res);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
return res;
|
||||
|
@ -174,8 +174,17 @@ test_read_lines_LF_valid_utf8 (void)
|
||||
gsize length = -1;
|
||||
line = g_data_input_stream_read_line_utf8 (G_DATA_INPUT_STREAM (stream), &length, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
if (line == NULL)
|
||||
break;
|
||||
{
|
||||
g_assert_cmpuint (length, ==, 0);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert_cmpuint (length, >, 0);
|
||||
}
|
||||
|
||||
n_lines++;
|
||||
g_free (line);
|
||||
}
|
||||
@ -207,11 +216,16 @@ test_read_lines_LF_invalid_utf8 (void)
|
||||
gsize length = -1;
|
||||
line = g_data_input_stream_read_line_utf8 (G_DATA_INPUT_STREAM (stream), &length, NULL, &error);
|
||||
if (n_lines == 0)
|
||||
g_assert_no_error (error);
|
||||
{
|
||||
/* First line is valid UTF-8 */
|
||||
g_assert_no_error (error);
|
||||
g_assert_cmpuint (length, ==, 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE);
|
||||
g_clear_error (&error);
|
||||
g_assert_cmpuint (length, ==, 0);
|
||||
g_free (line);
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user