|
|
e5da31 |
From 0ae8a90a40335257b4f7e1f44498a8b5d4f48aab Mon Sep 17 00:00:00 2001
|
|
|
e5da31 |
From: Philip Withnall <pwithnall@endlessos.org>
|
|
|
e5da31 |
Date: Thu, 4 Feb 2021 14:09:40 +0000
|
|
|
e5da31 |
Subject: [PATCH 11/12] giochannel: Forbid very long line terminator strings
|
|
|
e5da31 |
MIME-Version: 1.0
|
|
|
e5da31 |
Content-Type: text/plain; charset=UTF-8
|
|
|
e5da31 |
Content-Transfer-Encoding: 8bit
|
|
|
e5da31 |
|
|
|
e5da31 |
The public API `GIOChannel.line_term_len` is only a `guint`. Ensure that
|
|
|
e5da31 |
nul-terminated strings passed to `g_io_channel_set_line_term()` can’t
|
|
|
e5da31 |
exceed that length. Use `g_memdup2()` to avoid a warning (`g_memdup()`
|
|
|
e5da31 |
is due to be deprecated), but not to avoid a bug, since it’s also
|
|
|
e5da31 |
limited to `G_MAXUINT`.
|
|
|
e5da31 |
|
|
|
e5da31 |
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
|
|
|
e5da31 |
Helps: #2319
|
|
|
e5da31 |
---
|
|
|
e5da31 |
glib/giochannel.c | 17 +++++++++++++----
|
|
|
e5da31 |
1 file changed, 13 insertions(+), 4 deletions(-)
|
|
|
e5da31 |
|
|
|
e5da31 |
diff --git a/glib/giochannel.c b/glib/giochannel.c
|
|
|
e5da31 |
index ec2cada6f..908730fab 100644
|
|
|
e5da31 |
--- a/glib/giochannel.c
|
|
|
e5da31 |
+++ b/glib/giochannel.c
|
|
|
e5da31 |
@@ -885,16 +885,25 @@ g_io_channel_set_line_term (GIOChannel *channel,
|
|
|
e5da31 |
const gchar *line_term,
|
|
|
e5da31 |
gint length)
|
|
|
e5da31 |
{
|
|
|
e5da31 |
+ guint length_unsigned;
|
|
|
e5da31 |
+
|
|
|
e5da31 |
g_return_if_fail (channel != NULL);
|
|
|
e5da31 |
g_return_if_fail (line_term == NULL || length != 0); /* Disallow "" */
|
|
|
e5da31 |
|
|
|
e5da31 |
if (line_term == NULL)
|
|
|
e5da31 |
- length = 0;
|
|
|
e5da31 |
- else if (length < 0)
|
|
|
e5da31 |
- length = strlen (line_term);
|
|
|
e5da31 |
+ length_unsigned = 0;
|
|
|
e5da31 |
+ else if (length >= 0)
|
|
|
e5da31 |
+ length_unsigned = (guint) length;
|
|
|
e5da31 |
+ else
|
|
|
e5da31 |
+ {
|
|
|
e5da31 |
+ /* FIXME: We’re constrained by line_term_len being a guint here */
|
|
|
e5da31 |
+ gsize length_size = strlen (line_term);
|
|
|
e5da31 |
+ g_return_if_fail (length_size > G_MAXUINT);
|
|
|
e5da31 |
+ length_unsigned = (guint) length_size;
|
|
|
e5da31 |
+ }
|
|
|
e5da31 |
|
|
|
e5da31 |
g_free (channel->line_term);
|
|
|
e5da31 |
- channel->line_term = line_term ? g_memdup (line_term, length) : NULL;
|
|
|
e5da31 |
+ channel->line_term = line_term ? g_memdup2 (line_term, length_unsigned) : NULL;
|
|
|
e5da31 |
channel->line_term_len = length;
|
|
|
e5da31 |
}
|
|
|
e5da31 |
|
|
|
e5da31 |
--
|
|
|
e5da31 |
2.31.1
|
|
|
e5da31 |
|