From c49e3d227e4692c90c8e7d674388bafd9c2ecfe8 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 31 Dec 2003 23:41:06 +0000 Subject: (pthread_getattr_np): Make sure stack info returned for main thread does not overlap with any other VMA. --- nptl/pthread_getattr_np.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'nptl/pthread_getattr_np.c') diff --git a/nptl/pthread_getattr_np.c b/nptl/pthread_getattr_np.c index f66e97fa68..0e1082079a 100644 --- a/nptl/pthread_getattr_np.c +++ b/nptl/pthread_getattr_np.c @@ -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); -- cgit v1.2.3