diff options
author | Alexandre Oliva <aoliva@redhat.com> | 2012-10-10 07:05:10 -0300 |
---|---|---|
committer | Alexandre Oliva <aoliva@redhat.com> | 2012-10-10 07:05:10 -0300 |
commit | 4ba74a357376c8f8bf49487f96ae71cf2460c3f3 (patch) | |
tree | 785d54466a7b81a674cd69ee59c5e617f2d6101e /crypt/crypt_util.c | |
parent | 0e3b5d6a6859d74a18033d3a55e0ee92340437b3 (diff) | |
download | glibc-4ba74a357376c8f8bf49487f96ae71cf2460c3f3.tar.gz glibc-4ba74a357376c8f8bf49487f96ae71cf2460c3f3.tar.xz glibc-4ba74a357376c8f8bf49487f96ae71cf2460c3f3.zip |
* crypt/crypt-private.h: Include stdbool.h.
(_ufc_setup_salt_r): Return bool. * crypt/crypt-entry.c: Include errno.h. (__crypt_r): Return NULL with EINVAL for bad salt. * crypt/crypt_util.c (bad_for_salt): New. (_ufc_setup_salt_r): Check that salt is long enough and within the specified alphabet. * crypt/badsalttest.c: New file. * crypt/Makefile (tests): Add it. ($(objpfx)badsalttest): New.
Diffstat (limited to 'crypt/crypt_util.c')
-rw-r--r-- | crypt/crypt_util.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/crypt/crypt_util.c b/crypt/crypt_util.c index a1ff88b0da..e08dd8fa99 100644 --- a/crypt/crypt_util.c +++ b/crypt/crypt_util.c @@ -596,23 +596,55 @@ shuffle_sb(k, saltbits) #endif /* + * Return false iff C is in the specified alphabet for crypt salt. + */ + +static bool +bad_for_salt (char c) +{ + switch (c) + { + case '0' ... '9': + case 'A' ... 'Z': + case 'a' ... 'z': + case '.': case '/': + return false; + + default: + return true; + } +} + +/* * Setup the unit for a new salt * Hopefully we'll not see a new salt in each crypt call. + * Return false if an unexpected character was found in s[0] or s[1]. */ -void +bool _ufc_setup_salt_r(s, __data) const char *s; struct crypt_data * __restrict __data; { ufc_long i, j, saltbits; + char s0, s1; if(__data->initialized == 0) __init_des_r(__data); - if(s[0] == __data->current_salt[0] && s[1] == __data->current_salt[1]) - return; - __data->current_salt[0] = s[0]; __data->current_salt[1] = s[1]; + s0 = s[0]; + if(bad_for_salt (s0)) + return false; + + s1 = s[1]; + if(bad_for_salt (s1)) + return false; + + if(s0 == __data->current_salt[0] && s1 == __data->current_salt[1]) + return true; + + __data->current_salt[0] = s0; + __data->current_salt[1] = s1; /* * This is the only crypt change to DES: @@ -646,6 +678,8 @@ _ufc_setup_salt_r(s, __data) shuffle_sb((LONGG)__data->sb3, __data->current_saltbits ^ saltbits); __data->current_saltbits = saltbits; + + return true; } void |