[glib/cherry-pick-203e078f] Merge branch 'giochannel-check' into 'master'
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/cherry-pick-203e078f] Merge branch 'giochannel-check' into 'master'
- Date: Mon, 8 Feb 2021 11:08:21 +0000 (UTC)
commit d7299ed05fa70d00fc57fad493e22c3fee6eac72
Author: Sebastian Dröge <slomo coaxion net>
Date: Mon Feb 8 11:06:59 2021 +0000
Merge branch 'giochannel-check' into 'master'
giochannel: Fix length_size bounds check
Closes #2323
See merge request GNOME/glib!1931
(cherry picked from commit 203e078fdf31b147312da667cb6a4674e60ffbca)
a149bf2f giochannel: Fix length_size bounds check
5dc8b001 giochannel: Don't store negative line_term_len in GIOChannel struct
63f37f8c io-channel test: Add coverage for g_io_channel_set_line_term(., ., -1)
glib/giochannel.c | 4 ++--
glib/tests/io-channel.c | 6 ++++--
2 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/glib/giochannel.c b/glib/giochannel.c
index 4dec20f77..19bb06ba6 100644
--- a/glib/giochannel.c
+++ b/glib/giochannel.c
@@ -900,13 +900,13 @@ g_io_channel_set_line_term (GIOChannel *channel,
{
/* FIXME: We’re constrained by line_term_len being a guint here */
gsize length_size = strlen (line_term);
- g_return_if_fail (length_size > G_MAXUINT);
+ g_return_if_fail (length_size <= G_MAXUINT);
length_unsigned = (guint) length_size;
}
g_free (channel->line_term);
channel->line_term = line_term ? g_memdup2 (line_term, length_unsigned) : NULL;
- channel->line_term_len = length;
+ channel->line_term_len = length_unsigned;
}
/**
diff --git a/glib/tests/io-channel.c b/glib/tests/io-channel.c
index ff53fcef7..4a1b10876 100644
--- a/glib/tests/io-channel.c
+++ b/glib/tests/io-channel.c
@@ -49,8 +49,10 @@ test_read_line_embedded_nuls (void)
channel = g_io_channel_new_file (filename, "r", &local_error);
g_assert_no_error (local_error);
- /* Only break on newline characters, not nuls. */
- g_io_channel_set_line_term (channel, "\n", 1);
+ /* Only break on newline characters, not nuls.
+ * Use length -1 here to exercise glib#2323; the case where length > 0
+ * is covered in glib/tests/protocol.c. */
+ g_io_channel_set_line_term (channel, "\n", -1);
g_io_channel_set_encoding (channel, NULL, &local_error);
g_assert_no_error (local_error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]