[gnome-builder] libide/core: copy string before free



commit f11e149b4ae0a8954e4d66d2a91314242dfc7322
Author: Christian Hergert <chergert redhat com>
Date:   Fri Aug 12 21:52:37 2022 -0700

    libide/core: copy string before free
    
    This fixes situations where you could technically do something like
    ide_set_string(&self->foo, &self->foo[1]) which would otherwise result
    in a use-after-free.

 src/libide/core/ide-macros.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/core/ide-macros.h b/src/libide/core/ide-macros.h
index 8c20d858d..d319ec80f 100644
--- a/src/libide/core/ide-macros.h
+++ b/src/libide/core/ide-macros.h
@@ -91,11 +91,15 @@ static inline gboolean
 ide_set_string (char       **ptr,
                 const char  *str)
 {
+  char *copy;
+
   if (*ptr == str || g_strcmp0 (*ptr, str) == 0)
     return FALSE;
 
+  copy = g_strdup (str);
   g_clear_pointer (ptr, g_free);
-  *ptr = g_strdup (str);
+  *ptr = copy;
+
   return TRUE;
 }
 


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