diff options
author | Rich Salz <rsalz@openssl.org> | 2016-05-31 23:05:48 -0400 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2016-06-01 09:28:53 -0400 |
commit | 6493e4801e9edbe1ad1e256d4ce9cd55c8aa2242 (patch) | |
tree | 9c9dd96141769aa39819a962baaf5ce04a37e1a7 /crypto/des | |
parent | 1d54ef340864507c1b6e86238183ab4cbc7423aa (diff) | |
download | openssl-6493e4801e9edbe1ad1e256d4ce9cd55c8aa2242.tar.gz |
RT4337: Crash in DES
Salt must be two ASCII characters. Add tests to check for that,
and a test to test the checks.
Reviewed-by: Matt Caswell <matt@openssl.org>
Diffstat (limited to 'crypto/des')
-rw-r--r-- | crypto/des/fcrypt.c | 51 |
1 files changed, 18 insertions, 33 deletions
diff --git a/crypto/des/fcrypt.c b/crypto/des/fcrypt.c index b52f486acb..5215ad3e64 100644 --- a/crypto/des/fcrypt.c +++ b/crypto/des/fcrypt.c @@ -66,27 +66,23 @@ char *DES_crypt(const char *buf, const char *salt) char e_buf[32 + 1]; /* replace 32 by 8 ? */ char *ret; - /* Copy at most 2 chars of salt */ - if ((e_salt[0] = salt[0]) != '\0') - e_salt[1] = salt[1]; + if (salt[0] == '\0' || salt[1] == '\0') + return NULL; - /* Copy at most 32 chars of password */ - strncpy(e_buf, buf, sizeof(e_buf)); + /* Copy salt, convert to ASCII. */ + e_salt[0] = salt[0]; + e_salt[1] = salt[1]; + e_salt[2] = '\0'; + ebcdic2ascii(e_salt, e_salt, sizeof(e_salt)); - /* Make sure we have a delimiter */ - e_salt[sizeof(e_salt) - 1] = e_buf[sizeof(e_buf) - 1] = '\0'; - - /* Convert the e_salt to ASCII, as that's what DES_fcrypt works on */ - ebcdic2ascii(e_salt, e_salt, sizeof e_salt); - - /* Convert the cleartext password to ASCII */ + /* Convert password to ASCII. */ + OPENSSL_strlcpy(e_buf, buf, sizeof(e_buf)); ebcdic2ascii(e_buf, e_buf, sizeof e_buf); - /* Encrypt it (from/to ASCII) */ + /* Encrypt it (from/to ASCII); if it worked, convert back. */ ret = DES_fcrypt(e_buf, e_salt, buff); - - /* Convert the result back to EBCDIC */ - ascii2ebcdic(ret, ret, strlen(ret)); + if (ret != NULL) + ascii2ebcdic(ret, ret, strlen(ret)); return ret; #endif @@ -103,25 +99,14 @@ char *DES_fcrypt(const char *buf, const char *salt, char *ret) unsigned char *b = bb; unsigned char c, u; - /* - * eay 25/08/92 If you call crypt("pwd","*") as often happens when you - * have * as the pwd field in /etc/passwd, the function returns - * *\0XXXXXXXXX The \0 makes the string look like * so the pwd "*" would - * crypt to "*". This was found when replacing the crypt in our shared - * libraries. People found that the disabled accounts effectively had no - * passwd :-(. - */ -#ifndef CHARSET_EBCDIC - x = ret[0] = ((salt[0] == '\0') ? 'A' : salt[0]); + x = ret[0] = salt[0]; + if (x == 0 || x >= sizeof(con_salt)) + return NULL; Eswap0 = con_salt[x] << 2; - x = ret[1] = ((salt[1] == '\0') ? 'A' : salt[1]); + x = ret[1] = salt[1]; + if (x == 0 || x >= sizeof(con_salt)) + return NULL; Eswap1 = con_salt[x] << 6; -#else - x = ret[0] = ((salt[0] == '\0') ? os_toascii['A'] : salt[0]); - Eswap0 = con_salt[x] << 2; - x = ret[1] = ((salt[1] == '\0') ? os_toascii['A'] : salt[1]); - Eswap1 = con_salt[x] << 6; -#endif /* * EAY r=strlen(buf); r=(r+7)/8; |