diff options
author | davidxu <davidxu@FreeBSD.org> | 2003-07-07 04:28:23 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2003-07-07 04:28:23 +0000 |
commit | 8aa4e2d6856d1eed699b30ccca6163f8e501e183 (patch) | |
tree | 6539674ba4c0ff3018faf64006ac81eb9090ec5f /lib/libpthread/thread/thr_cancel.c | |
parent | e95dd66c1f7fd662d47b34b5d83f1dcaa8b150e3 (diff) | |
download | FreeBSD-src-8aa4e2d6856d1eed699b30ccca6163f8e501e183.zip FreeBSD-src-8aa4e2d6856d1eed699b30ccca6163f8e501e183.tar.gz |
Avoid accessing user provided parameters in critical region.
Reviewed by: deischen
Diffstat (limited to 'lib/libpthread/thread/thr_cancel.c')
-rw-r--r-- | lib/libpthread/thread/thr_cancel.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/libpthread/thread/thr_cancel.c b/lib/libpthread/thread/thr_cancel.c index 085f349..905891c 100644 --- a/lib/libpthread/thread/thr_cancel.c +++ b/lib/libpthread/thread/thr_cancel.c @@ -146,16 +146,12 @@ _pthread_setcancelstate(int state, int *oldstate) switch (state) { case PTHREAD_CANCEL_ENABLE: - if (oldstate != NULL) - *oldstate = ostate; curthread->cancelflags &= ~PTHREAD_CANCEL_DISABLE; if ((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0) need_exit = checkcancel(curthread); ret = 0; break; case PTHREAD_CANCEL_DISABLE: - if (oldstate != NULL) - *oldstate = ostate; curthread->cancelflags |= PTHREAD_CANCEL_DISABLE; ret = 0; break; @@ -169,6 +165,9 @@ _pthread_setcancelstate(int state, int *oldstate) pthread_exit(PTHREAD_CANCELED); PANIC("cancel"); } + if (ret == 0 && oldstate != NULL) + *oldstate = ostate; + return (ret); } @@ -186,15 +185,11 @@ _pthread_setcanceltype(int type, int *oldtype) otype = curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS; switch (type) { case PTHREAD_CANCEL_ASYNCHRONOUS: - if (oldtype != NULL) - *oldtype = otype; curthread->cancelflags |= PTHREAD_CANCEL_ASYNCHRONOUS; need_exit = checkcancel(curthread); ret = 0; break; case PTHREAD_CANCEL_DEFERRED: - if (oldtype != NULL) - *oldtype = otype; curthread->cancelflags &= ~PTHREAD_CANCEL_ASYNCHRONOUS; ret = 0; break; @@ -208,6 +203,9 @@ _pthread_setcanceltype(int type, int *oldtype) pthread_exit(PTHREAD_CANCELED); PANIC("cancel"); } + if (ret == 0 && oldtype != NULL) + *oldtype = otype; + return (ret); } |