From cb6207858a9fcc2feaee22e626912fba281ac969 Mon Sep 17 00:00:00 2001 From: raf Date: Tue, 20 Mar 2007 17:29:57 -0700 Subject: PSARC 2007/129 thr_keycreate_once 6513516 double checked locking code needs a memory barrier --- usr/src/lib/libcrypt/common/des_crypt.c | 40 +++++++++++++++------------------ 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'usr/src/lib/libcrypt') diff --git a/usr/src/lib/libcrypt/common/des_crypt.c b/usr/src/lib/libcrypt/common/des_crypt.c index 69a7f83152..ceb64a1f98 100644 --- a/usr/src/lib/libcrypt/common/des_crypt.c +++ b/usr/src/lib/libcrypt/common/des_crypt.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,14 +19,14 @@ * CDDL HEADER END */ -/* Copyright (c) 1988 AT&T */ -/* All Rights Reserved */ - /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + #pragma ident "%Z%%M% %I% %E% SMI" /*LINTLIBRARY*/ @@ -42,7 +41,7 @@ #include #include -#include +#include #include /* EXPORT DELETE START */ @@ -330,22 +329,18 @@ des_encrypt(char *block, int edflag) #define IOBUF_SIZE 16 static char * -_get_iobuf(thread_key_t *key, unsigned size) +_get_iobuf(thread_key_t *keyp, unsigned size) { - char *iobuf = NULL; - - if (thr_getspecific(*key, (void **)&iobuf) != 0) { - if (thr_keycreate(key, free) != 0) { - return (NULL); - } - } + char *iobuf; - if (!iobuf) { - if (thr_setspecific(*key, (void *)(iobuf = malloc(size))) - != 0) { + if (thr_keycreate_once(keyp, free) != 0) + return (NULL); + iobuf = pthread_getspecific(*keyp); + if (iobuf == NULL) { + if (thr_setspecific(*keyp, (iobuf = malloc(size))) != 0) { if (iobuf) (void) free(iobuf); - return (NULL); + iobuf = NULL; } } return (iobuf); @@ -357,8 +352,9 @@ des_crypt(const char *pw, const char *salt) /* EXPORT DELETE START */ int i, j; char c, temp; - static thread_key_t key = 0; - char block[66], *iobuf = _get_iobuf(&key, IOBUF_SIZE); + char block[66]; + static thread_key_t key = THR_ONCE_KEY; + char *iobuf = _get_iobuf(&key, IOBUF_SIZE); (void) mutex_lock(&lock); for (i = 0; i < 66; i++) -- cgit v1.2.3