changeset 18036:b3833d5cf7e0

selinux-h: avoid double free after *getfilecon() Originally reported by Ben Shelton on bug-tar: http://lists.gnu.org/archive/html/bug-tar/2015-04/msg00009.html * lib/getfilecon.c (map_to_failure): Set the already freed '*con' pointer to NULL. Man getfilecon(3) says that any non-NULL '*con' parameter should be freed by freecon(3) (regardless the return value).
author Pavel Raiskup <praiskup@redhat.com>
date Wed, 01 Jul 2015 12:30:57 +0200
parents 674bd7704497
children 8feafebf1ed4
files ChangeLog lib/getfilecon.c
diffstat 2 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2015-07-01  Pavel Raiskup  <praiskup@redhat.com>
+
+	selinux-h: avoid double free after *getfilecon()
+	Originally reported by Ben Shelton on bug-tar:
+	http://lists.gnu.org/archive/html/bug-tar/2015-04/msg00009.html
+	* lib/getfilecon.c (map_to_failure): Set the already freed '*con'
+	pointer to NULL.  Man getfilecon(3) says that any non-NULL '*con'
+	param should be freed by freecon(3) (regardless the return value).
+
 2015-07-01  Pavel Fedin  <p.fedin@samsung.com>
 
 	fix pty related tests issues on Windows (trivial)
--- a/lib/getfilecon.c
+++ b/lib/getfilecon.c
@@ -57,6 +57,7 @@
   if (ret == 10 && strcmp (*con, "unlabeled") == 0)
     {
       freecon (*con);
+      *con = NULL;
       errno = ENODATA;
       return -1;
     }