summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Hergert <chergert@redhat.com>2023-04-26 16:42:40 -0700
committerChristian Hergert <chergert@redhat.com>2023-04-27 09:18:00 -0700
commit4787242566faace0640281c9fde2751ebe6838b5 (patch)
tree0ed4f63d25b65fdda548a9e6d235aff8d5a97eab
parente8f0f8ead93ff3ff8819ef1c68505f44a8fbcd10 (diff)
downloadgtksourceview-4-8.tar.gz
bufferoutputstream: be defensive about dereferencing nul bytegtksourceview-4-8
If we don't own the buffer, then we don't have a guarantee that the buffer is one byte bigger than any count/length we've received. Mke sure to only dereference that byte when we do. Related #309
-rw-r--r--gtksourceview/gtksourcebufferoutputstream.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/gtksourceview/gtksourcebufferoutputstream.c b/gtksourceview/gtksourcebufferoutputstream.c
index 77a2a113..26143d96 100644
--- a/gtksourceview/gtksourcebufferoutputstream.c
+++ b/gtksourceview/gtksourcebufferoutputstream.c
@@ -656,7 +656,8 @@ validate_and_insert (GtkSourceBufferOutputStream *stream,
apply_error_tag (stream);
- if ((nvalid != len || !owned) && buffer[nvalid] != '\0')
+ if (!owned ||
+ (nvalid != len && buffer[nvalid] != '\0'))
{
/* make sure the buffer is always properly null
* terminated. This is needed, at least for now,