Skip to content

Commit

Permalink
Make crypt and crypt_gensalt use thread-local output buffers.
Browse files Browse the repository at this point in the history
This change makes crypt and crypt_gensalt as thread-safe as
they can be without changing their interfaces.  Solaris
already made this change, and it’s being discussed by glibc
(with suggestion that it should be pushed upstream to the C
and POSIX standards committees):
https://sourceware.org/ml/libc-alpha/2018-10/msg00437.html

Portable programs should still use the r-variants, though,
because this is not a guaranteed feature that is portable
to other implementations of these functions. Also it doesn’t
help threads to not clobber their corresponding output buffer
on a second call from within the same thread.
  • Loading branch information
besser82 committed Jan 14, 2025
1 parent 88ecfa5 commit b62b5a0
Show file tree
Hide file tree
Showing 11 changed files with 892 additions and 15 deletions.
15 changes: 12 additions & 3 deletions LICENSING
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ source tree. For specific licensing terms consult the files themselves.
* Public domain, written by Zack Weinberg et al.:
byteorder.h, randombytes.c, test-byteorder.c
test-alg-pbkdf-hmac-sha256.c
test-badsetting.c, test-crypt-badargs.c, test-getrandom-fallbacks.c,
test-getrandom-interface.c, test-symbols-compat.sh,
test-symbols-renames.sh, test-symbols-static.sh,
test-badsetting.c, test-crypt-badargs.c, test-crypt-multithread.c,
test-getrandom-fallbacks.c, test-getrandom-interface.c,
test-symbols-compat.sh, test-symbols-renames.sh,
test-symbols-static.sh,
build-aux/scripts/gen-crypt-h,
build-aux/scripts/gen-crypt-symbol-vers-h,
build-aux/scripts/gen-libcrypt-map,
Expand All @@ -88,6 +89,14 @@ source tree. For specific licensing terms consult the files themselves.
GPL (v3 or later), with Autoconf exception:
build-aux/m4/zw_automodern.m4, build-aux/m4/zw_simple_warnings.m4

* Copyright Steven G. Johnson, Daniel Richard G., Marc Stevens;
GPL (v3 or later), with Autoconf exception:
build-aux/m4/ax_pthread.m4

* Copyright Alan Woodland, Diego Elio Petteno;
GPL (v3 or later), with Autoconf exception:
build-aux/m4/ax_tls.m4

* Copyright <vt at altlinux.org>; 0-clause BSD:
crypt-yescrypt.c, test-crypt-yescrypt.c

Expand Down
6 changes: 6 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ check_PROGRAMS = \
test/compile-strong-alias \
test/crypt-badargs \
test/crypt-gost-yescrypt \
test/crypt-multithread \
test/explicit-bzero \
test/gensalt \
test/gensalt-extradata \
Expand Down Expand Up @@ -478,6 +479,10 @@ test/symbols-compat.log test/symbols-compat.trs: test/TestCommon.pm
test/symbols-renames.log test/symbols-renames.trs: test/TestCommon.pm
test/symbols-static.log test/symbols-static.trs: test/TestCommon.pm

# test/crypt-multithread.c uses pthreads.
test_crypt_multithread_CFLAGS = $(PTHREAD_CFLAGS)
test_crypt_multithread_LIBS = $(PTHREAD_LIBS)

COMMON_TEST_OBJECTS = libcrypt.la

test_badsalt_LDADD = $(COMMON_TEST_OBJECTS)
Expand All @@ -488,6 +493,7 @@ test_checksalt_LDADD = $(COMMON_TEST_OBJECTS)
test_des_obsolete_LDADD = $(COMMON_TEST_OBJECTS)
test_des_obsolete_r_LDADD = $(COMMON_TEST_OBJECTS)
test_crypt_badargs_LDADD = $(COMMON_TEST_OBJECTS)
test_crypt_multithread_LDADD = $(COMMON_TEST_OBJECTS)
test_short_outbuf_LDADD = $(COMMON_TEST_OBJECTS)
test_preferred_method_LDADD = $(COMMON_TEST_OBJECTS)
test_special_char_salt_LDADD = $(COMMON_TEST_OBJECTS)
Expand Down
Loading

0 comments on commit b62b5a0

Please sign in to comment.