]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(pthread_getattr_np): Make sure stack info returned for main thread does not overlap...
authorUlrich Drepper <drepper@redhat.com>
Wed, 31 Dec 2003 23:41:06 +0000 (23:41 +0000)
committerUlrich Drepper <drepper@redhat.com>
Wed, 31 Dec 2003 23:41:06 +0000 (23:41 +0000)
nptl/pthread_getattr_np.c

index f66e97fa68703ac274b54f168c9fca77070b7a6f..0e1082079a3e484d08e457eb359cb6a5add41b7e 100644 (file)
@@ -98,6 +98,7 @@ pthread_getattr_np (thread_id, attr)
 
          char *line = NULL;
          size_t linelen = 0;
+         uintptr_t last_to = 0;
 
          while (! feof_unlocked (fp))
            {
@@ -106,23 +107,25 @@ pthread_getattr_np (thread_id, attr)
 
              uintptr_t from;
              uintptr_t to;
-             if (sscanf (line, "%" SCNxPTR "-%" SCNxPTR, &from, &to) == 2
-                 && from <= (uintptr_t) __libc_stack_end
+             if (sscanf (line, "%" SCNxPTR "-%" SCNxPTR, &from, &to) != 2)
+               continue;
+             if (from <= (uintptr_t) __libc_stack_end
                  && (uintptr_t) __libc_stack_end < to)
                {
                  /* Found the entry.  Now we have the info we need.  */
                  iattr->stacksize = rl.rlim_cur;
                  iattr->stackaddr = (void *) to;
 
-                 /* The limit might be too high.  This is a bogus
-                    situation but try to avoid making it worse.  */
-                 if ((size_t) iattr->stacksize > (size_t) iattr->stackaddr)
-                   iattr->stacksize = (size_t) iattr->stackaddr;
+                 /* The limit might be too high.  */
+                 if ((size_t) iattr->stacksize
+                     > (size_t) iattr->stackaddr - last_to)
+                   iattr->stacksize = (size_t) iattr->stackaddr - last_to;
 
                  /* We succeed and no need to look further.  */
                  ret = 0;
                  break;
                }
+             last_to = to;
            }
 
          fclose (fp);