[glib/wip/smcv/issue1923: 5/5] goption: Relax assertion to avoid being broken by kdeinit5



commit 00210aad87d90c4076d6c36496a2b40024181a07
Author: Simon McVittie <smcv collabora com>
Date:   Thu Oct 31 13:35:58 2019 +0000

    goption: Relax assertion to avoid being broken by kdeinit5
    
    kdeinit5 overwrites argv, which in turn results in /proc/self/cmdline
    being overwritten. It seems that this is done in a way that does not
    necessarily guarantee that /proc/self/cmdline will end up NUL-terminated.
    
    However, g_file_get_contents() is documented to fill a buffer of size
    len + 1, where buffer[len] == '\0', even if the file's actual contents
    (from buffer[0] to buffer[len-1] inclusive) did not include a NUL;
    so we can safely relax this assertion slightly.
    
    Resolves: https://gitlab.gnome.org/GNOME/glib/issues/1923
    Signed-off-by: Simon McVittie <smcv collabora com>

 glib/goption.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/glib/goption.c b/glib/goption.c
index 587eb1fb4..b0fb80c94 100644
--- a/glib/goption.c
+++ b/glib/goption.c
@@ -1833,8 +1833,10 @@ platform_get_argv0 (void)
                            NULL))
     return NULL;
 
-  /* Sanity check for a NUL terminator. */
-  g_assert (memchr (cmdline, 0, len));
+  /* g_file_get_contents() guarantees to put a NUL immediately after the
+   * file's contents (at cmdline[len] here), even if the file itself was
+   * not NUL-terminated. */
+  g_assert (memchr (cmdline, 0, len + 1));
 
   /* We could just return cmdline, but I think it's better
    * to hold on to a smaller malloc block; the arguments


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]