diff options
author | Ed Schouten <ed@FreeBSD.org> | 2016-08-10 15:16:28 +0000 |
---|---|---|
committer | Ed Schouten <ed@FreeBSD.org> | 2016-08-10 15:16:28 +0000 |
commit | 5f521d7ba72145092ea23ff6081d8791ad6c1f9d (patch) | |
tree | 80c95ae1764bc54824036934952da43ecbf095e2 /lib/libcrypt/misc.c | |
parent | 3a77833e87a68b01242cfe5f7d0002be04f1a0b0 (diff) | |
download | src-5f521d7ba72145092ea23ff6081d8791ad6c1f9d.tar.gz src-5f521d7ba72145092ea23ff6081d8791ad6c1f9d.zip |
Make libcrypt thread-safe. Add crypt_r(3).
glibc has a pretty nice function called crypt_r(3), which is nothing
more than crypt(3), but thread-safe. It accomplishes this by introducing
a 'struct crypt_data' structure that contains a buffer that is large
enough to hold the resulting string.
Let's go ahead and also add this function. It would be a shame if a
useful function like this wouldn't be usable in multithreaded apps.
Refactor crypt.c and all of the backends to no longer declare static
arrays, but write their output in a provided buffer.
There is no need to do any buffer length computation here, as we'll just
need to ensure that 'struct crypt_data' is large enough, which it is.
_PASSWORD_LEN is defined to 128 bytes, but in this case I'm picking 256,
as this is going to be part of the actual ABI.
Differential Revision: https://reviews.freebsd.org/D7306
Notes
Notes:
svn path=/head/; revision=303920
Diffstat (limited to 'lib/libcrypt/misc.c')
-rw-r--r-- | lib/libcrypt/misc.c | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/lib/libcrypt/misc.c b/lib/libcrypt/misc.c index 0f63ce04214c..2202ffb652cd 100644 --- a/lib/libcrypt/misc.c +++ b/lib/libcrypt/misc.c @@ -47,7 +47,7 @@ _crypt_to64(char *s, u_long v, int n) } void -b64_from_24bit(uint8_t B2, uint8_t B1, uint8_t B0, int n, int *buflen, char **cp) +b64_from_24bit(uint8_t B2, uint8_t B1, uint8_t B0, int n, char **cp) { uint32_t w; int i; @@ -56,8 +56,6 @@ b64_from_24bit(uint8_t B2, uint8_t B1, uint8_t B0, int n, int *buflen, char **cp for (i = 0; i < n; i++) { **cp = itoa64[w&0x3f]; (*cp)++; - if ((*buflen)-- < 0) - break; w >>= 6; } } |