Skip to contentSkip to conversation

gnome-desktop3: eliminate erroneous free()

PATCH In review Joe Slater 2 participants 2 messages Mar 6, 2018

lore
Share & tools
lore

Joe Slater

author
#0 lore raw

PATCH 1/1 gnome-desktop3: eliminate erroneous free()

gnome-desktop-thumbnail-don-t-convert-time_t-to-long.patch introduced a call to localtime() and a free() of the structure returned. This is incorrect, as the structure is static. For glibc 2.26, this will cause the program to abort. Eliminate the free() and call localtime_r() which lets us allocate the tm structure.

---
 .../gnome-desktop/fix_erroneous_free.patch         | 35 ++++++++++++++++++++++
 .../gnome-desktop/gnome-desktop3_3.26.2.bb         |  1 +
 2 files changed, 36 insertions(+)
 create mode 100644 meta/recipes-gnome/gnome-desktop/gnome-desktop/fix_erroneous_free.patch
meta/recipes-gnome/gnome-desktop/gnome-desktop/fix_erroneous_free.patch new file +35 -0
new file mode 100644
index 0000000..c27e4d5
@@ -0,0 +1,35 @@
+gnome-desktop3: eliminate erroneous free()
+
+Do not free() a static structure.  Use re-entrant localtime_r().
+
+Upstream-Status: Pending
+
+Signed-off-by: Joe Slater <[email protected]>
+
+
+--- a/libgnome-desktop/gnome-desktop-thumbnail.c
++++ b/libgnome-desktop/gnome-desktop-thumbnail.c
+@@ -1200,7 +1200,7 @@ save_thumbnail (GdkPixbuf  *pixbuf,
+   char *tmp_path = NULL;
+   int tmp_fd;
+   char mtime_str[21];
+-  struct tm *tmp_mtime = NULL;
++  struct tm tmp_mtime;
+   gboolean ret = FALSE;
+   GError *error = NULL;
+   const char *width, *height;
+@@ -1220,11 +1220,10 @@ save_thumbnail (GdkPixbuf  *pixbuf,
+     goto out;
+   close (tmp_fd);
+ 
+-  tmp_mtime = localtime (&mtime);
+-  if (!tmp_mtime)
++  if (!localtime_r (&mtime,&tmp_mtime))
+     goto out;
+-  strftime (mtime_str, 21, "%s", tmp_mtime);
+-  free (tmp_mtime);
++
++  strftime (mtime_str, 21, "%s", &tmp_mtime);
+   width = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::Image::Width");
+   height = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::Image::Height");
+ 
meta/recipes-gnome/gnome-desktop/gnome-desktop3_3.26.2.bb +1 -0
index cd6c194..2cd3234 100644
@@ -14,6 +14,7 @@ SRC_URI += " \
            file://gnome-desktop-thumbnail-don-t-convert-time_t-to-long.patch \
            file://0001-configure.ac-Remove-gnome-common-macro-calls.patch \
            file://0001-Disable-libseccomp-sycall-filtering-mechanism.patch \
+           file://fix_erroneous_free.patch \
            "
 
 DEPENDS += "intltool-native gsettings-desktop-schemas gconf virtual/libx11 gtk+3 glib-2.0 startup-notification xkeyboard-config iso-codes udev"
Signature · 1 line
2.7.4
#1 lore raw

Please don't patch a patch, but fix the patch.

Ross

Quoted 85 lines · Joe Slater

gnome-desktop-thumbnail-don-t-convert-time_t-to-long.patch introduced a call to localtime() and a free() of the structure returned. This is incorrect, as the structure is static. For glibc 2.26, this will cause the program to abort. Eliminate the free() and call localtime_r() which lets us allocate the tm structure.

---
 .../gnome-desktop/fix_erroneous_free.patch         | 35
++++++++++++++++++++++
 .../gnome-desktop/gnome-desktop3_3.26.2.bb         |  1 +
 2 files changed, 36 insertions(+)
 create mode 100644 meta/recipes-gnome/gnome-desktop/gnome-desktop/fix_

erroneous_free.patch

meta/recipes-gnome/gnome-desktop/gnome-desktop/fix_ new file +0 -0
new file mode 100644
index 0000000..c27e4d5

erroneous_free.patch

meta/recipes-gnome/gnome-desktop/gnome-desktop/fix_ new file +35 -0
@@ -0,0 +1,35 @@
+gnome-desktop3: eliminate erroneous free()
+
+Do not free() a static structure.  Use re-entrant localtime_r().
+
+Upstream-Status: Pending
+
+Signed-off-by: Joe Slater <[email protected]>
+
+
+--- a/libgnome-desktop/gnome-desktop-thumbnail.c
++++ b/libgnome-desktop/gnome-desktop-thumbnail.c
+@@ -1200,7 +1200,7 @@ save_thumbnail (GdkPixbuf  *pixbuf,
+   char *tmp_path = NULL;
+   int tmp_fd;
+   char mtime_str[21];
+-  struct tm *tmp_mtime = NULL;
++  struct tm tmp_mtime;
+   gboolean ret = FALSE;
+   GError *error = NULL;
+   const char *width, *height;
+@@ -1220,11 +1220,10 @@ save_thumbnail (GdkPixbuf  *pixbuf,
+     goto out;
+   close (tmp_fd);
+
+-  tmp_mtime = localtime (&mtime);
+-  if (!tmp_mtime)
++  if (!localtime_r (&mtime,&tmp_mtime))
+     goto out;
+-  strftime (mtime_str, 21, "%s", tmp_mtime);
+-  free (tmp_mtime);
++
++  strftime (mtime_str, 21, "%s", &tmp_mtime);
+   width = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::Image::Width");
+   height = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::Image::Height");
+
meta/recipes-gnome/gnome-desktop/gnome-desktop3_3.26.2.bb +1 -0
index cd6c194..2cd3234 100644
@@ -14,6 +14,7 @@ SRC_URI += " \
            file://gnome-desktop-thumbnail-don-t-convert-time_t-to-long.patch
 \
            file://0001-configure.ac-Remove-gnome-common-macro-calls.patch
 \
            file://0001-Disable-libseccomp-sycall-filtering-mechanism.patch
 \
+           file://fix_erroneous_free.patch \
            "

DEPENDS += "intltool-native gsettings-desktop-schemas gconf
virtual/libx11 gtk+3 glib-2.0 startup-notification xkeyboard-config iso-codes udev"
--
2.7.4

--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core