From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23680 invoked by alias); 22 Jun 2007 10:05:44 -0000 Received: (qmail 23661 invoked by uid 22791); 22 Jun 2007 10:05:43 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 22 Jun 2007 10:05:40 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l5MA9mH7007674; Fri, 22 Jun 2007 12:09:48 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l5MA9mVE007667; Fri, 22 Jun 2007 12:09:48 +0200 Date: Fri, 22 Jun 2007 10:05:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix pthread_getattr_np Message-ID: <20070622100947.GE3081@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-06/txt/msg00018.txt.bz2 Hi! My reading of pthread_getattr_np is that following code will crash: pthread_attr_t attr; memset (&attr, 0xaa, sizeof (attr)); // Stress that attr is uninitialized if (pthread_getattr_np (pthread_self (), &attr) == 0) pthread_attr_destroy (&attr); if sched_getaffinity returns ENOSYS. One way to fix this is below, another would be e.g. to clear whole pthread_attr_t at the start of pthread_getattr_np. That could cure even crashes on invalid careless code like e.g. boehm-gc does: my_pthread = pthread_self(); pthread_getattr_np (my_pthread, &attr); pthread_attr_getstack (&attr, (void **) &stack_addr, &stack_size); pthread_attr_destroy (&attr); (which has to be fixed anyway). 2007-06-22 Jakub Jelinek * pthread_getattr_np.c (pthread_getattr_np): Clear cpuset and cpusetsize if pthread_getaffinity_np failed with ENOSYS. --- libc/nptl/pthread_getattr_np.c.jj 2007-06-04 08:42:05.000000000 +0200 +++ libc/nptl/pthread_getattr_np.c 2007-06-22 11:41:48.000000000 +0200 @@ -164,8 +164,12 @@ pthread_getattr_np (thread_id, attr) { free (cpuset); if (ret == ENOSYS) - /* There is no such functionality. */ - ret = 0; + { + /* There is no such functionality. */ + ret = 0; + iattr->cpuset = NULL; + iattr->cpusetsize = 0; + } } } Jakub