public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix pthread_getattr_np
Date: Mon, 22 Mar 2004 18:16:00 -0000	[thread overview]
Message-ID: <20040322121918.GB15946@sunsite.ms.mff.cuni.cz> (raw)

Hi!

On systems with more than 32 * 8 CPUs pthread_getattr_np would get into an
endless loop.  Furthermore, if realloc fails, we certainly shouldn't
dereference NULL pointer, but break out of the loop (free (cpuset) is done
after the loop on failures).
The other change is just trying to avoid buffer overflows on systems with
more than 16 billion CPUs (res is a signed value, so if kernel returned
non-error, but bigger than INT_MAX, the following memcpy would do the wrong
thing on 64-bit arches (clear some area beyond end of buffer)).

2004-03-22  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/unix/sysv/linux/pthread_getaffinity.c
	(__pthread_getaffinity_new): Use INT_MAX instead of UINT_MAX.
	* pthread_getattr_np.c (pthread_getattr_np): Double size every cycle.
	If realloc fails, break out of the loop.

--- libc/nptl/sysdeps/unix/sysv/linux/pthread_getaffinity.c.jj	2004-03-22 14:45:57.000000000 +0100
+++ libc/nptl/sysdeps/unix/sysv/linux/pthread_getaffinity.c	2004-03-22 15:18:42.402868578 +0100
@@ -34,7 +34,7 @@ __pthread_getaffinity_new (pthread_t th,
 
   INTERNAL_SYSCALL_DECL (err);
   int res = INTERNAL_SYSCALL (sched_getaffinity, err, 3, pd->tid,
-			      MIN (UINT_MAX, cpusetsize), cpuset);
+			      MIN (INT_MAX, cpusetsize), cpuset);
   if (INTERNAL_SYSCALL_ERROR_P (res, err))
     return INTERNAL_SYSCALL_ERRNO (res, err);
 
--- libc/nptl/pthread_getattr_np.c.jj	2004-03-22 14:42:35.000000000 +0100
+++ libc/nptl/pthread_getattr_np.c	2004-03-22 15:11:39.416215690 +0100
@@ -135,16 +135,18 @@ pthread_getattr_np (thread_id, attr)
 
   if (ret == 0)
     {
-      size_t size = 32;
+      size_t size = 16;
       cpu_set_t *cpuset = NULL;
 
       do
 	{
+	  size <<= 1;
+
 	  void *newp = realloc (cpuset, size);
 	  if (newp == NULL)
 	    {
-	      free (cpuset);
 	      ret = ENOMEM;
+	      break;
 	    }
 	  cpuset = (cpu_set_t *) newp;
 

	Jakub

             reply	other threads:[~2004-03-22 14:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-22 18:16 Jakub Jelinek [this message]
2007-06-22 10:05 Jakub Jelinek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040322121918.GB15946@sunsite.ms.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).