From 25b7ecf895b968e9275ecd527e68d648a59ed52a Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 2 May 2024 15:59:46 +0100 Subject: [PATCH] gitypelib: Fix iterating through typelib prefixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The iteration code used `g_string_overwrite_len()` to try and simplify buffer allocation and growth, but seemingly forgot to handle the fact that it doesn’t nul-terminate what it overwrites: the method is intended to be used to splice bits into longer strings, not to overwrite an entire nul-terminated string. This meant that when iterating over a comma-separated `c_prefix` like `GUnix,G`, on the second iteration `g_string_overwrite_len()` would be used to write `G` into index 0 of the already-set `GUnix` string in the buffer, leading to the first iteration happening all over again and the `G` prefix being ignored. This led to symbols failing to be matched to the `GioUnix` typelib, even though they should have been. This will be checked by a test in the following commit. Signed-off-by: Philip Withnall Helps: #3303 --- girepository/gitypelib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/girepository/gitypelib.c b/girepository/gitypelib.c index 3c88a79e6..57411a86b 100644 --- a/girepository/gitypelib.c +++ b/girepository/gitypelib.c @@ -316,7 +316,8 @@ strsplit_iter_next (StrSplitIter *iter, } else { - g_string_overwrite_len (&iter->buf, 0, s, (gssize)len); + g_string_overwrite_len (&iter->buf, 0, s, (gssize)len + 1); + iter->buf.str[len] = '\0'; *out_val = iter->buf.str; } return TRUE;