3bda5c
Fix use of __pthread_attr_copy in mq_notify (bug 27896)
3bda5c
3bda5c
__pthread_attr_copy can fail and does not initialize the attribute
3bda5c
structure in that case.
3bda5c
3bda5c
If __pthread_attr_copy is never called and there is no allocated
3bda5c
attribute, pthread_attr_destroy should not be called, otherwise
3bda5c
there is a null pointer dereference in rt/tst-mqueue6.
3bda5c
3bda5c
Fixes commit 42d359350510506b87101cf77202fefcbfc790cb
3bda5c
("Use __pthread_attr_copy in mq_notify (bug 27896)").
3bda5c
3bda5c
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
3bda5c
(cherry picked from commit 217b6dc298156bdb0d6aea9ea93e7e394a5ff091)
3bda5c
3bda5c
diff --git a/sysdeps/unix/sysv/linux/mq_notify.c b/sysdeps/unix/sysv/linux/mq_notify.c
3bda5c
index c4091169306ffde8..45449571d14c379f 100644
3bda5c
--- a/sysdeps/unix/sysv/linux/mq_notify.c
3bda5c
+++ b/sysdeps/unix/sysv/linux/mq_notify.c
3bda5c
@@ -260,7 +260,14 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification)
3bda5c
       if (data.attr == NULL)
3bda5c
 	return -1;
3bda5c
 
3bda5c
-      __pthread_attr_copy (data.attr, notification->sigev_notify_attributes);
3bda5c
+      int ret = __pthread_attr_copy (data.attr,
3bda5c
+				     notification->sigev_notify_attributes);
3bda5c
+      if (ret != 0)
3bda5c
+	{
3bda5c
+	  free (data.attr);
3bda5c
+	  __set_errno (ret);
3bda5c
+	  return -1;
3bda5c
+	}
3bda5c
     }
3bda5c
 
3bda5c
   /* Construct the new request.  */
3bda5c
@@ -273,7 +280,7 @@ mq_notify (mqd_t mqdes, const struct sigevent *notification)
3bda5c
   int retval = INLINE_SYSCALL (mq_notify, 2, mqdes, &se);
3bda5c
 
3bda5c
   /* If it failed, free the allocated memory.  */
3bda5c
-  if (__glibc_unlikely (retval != 0))
3bda5c
+  if (retval != 0 && data.attr != NULL)
3bda5c
     {
3bda5c
       pthread_attr_destroy (data.attr);
3bda5c
       free (data.attr);