diff options
author | Michael Cahill <michael.cahill@mongodb.com> | 2015-05-14 15:27:24 +1000 |
---|---|---|
committer | Michael Cahill <michael.cahill@mongodb.com> | 2015-05-14 15:27:24 +1000 |
commit | 77163ad484394a444ebe7642e72f15bc9c78fbec (patch) | |
tree | b2c41b4776c93157daee5cadcb8b121ef3ac2acc | |
parent | f0c0fa38fcc0e0bb36e7055554a821ffad57b5f8 (diff) | |
download | mongo-77163ad484394a444ebe7642e72f15bc9c78fbec.tar.gz |
Avoid islower / isupper in the ROTN code: it behaves in unexpected ways on various systems, particularly if the locale is not "C".
refs WT-1822
-rw-r--r-- | dist/s_string.ok | 1 | ||||
-rw-r--r-- | ext/encryptors/rotn/rotn_encrypt.c | 12 |
2 files changed, 8 insertions, 5 deletions
diff --git a/dist/s_string.ok b/dist/s_string.ok index 79ec77aae22..74685836024 100644 --- a/dist/s_string.ok +++ b/dist/s_string.ok @@ -415,6 +415,7 @@ crc crypto cryptobad ctime +ctype curbackup curbulk curconfig diff --git a/ext/encryptors/rotn/rotn_encrypt.c b/ext/encryptors/rotn/rotn_encrypt.c index 409278a0346..503dcae83a7 100644 --- a/ext/encryptors/rotn/rotn_encrypt.c +++ b/ext/encryptors/rotn/rotn_encrypt.c @@ -26,7 +26,6 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#include <ctype.h> #include <errno.h> #include <stdlib.h> #include <string.h> @@ -129,11 +128,14 @@ do_rotate(char *buf, size_t len, int rotn) uint32_t i; /* * Now rotate. + * + * Avoid ctype functions because they behave in unexpected ways, + * particularly when the locale is not "C". */ for (i = 0; i < len; i++) { - if (islower(buf[i])) + if ('a' <= buf[i] && buf[i] <= 'z') buf[i] = ((buf[i] - 'a') + rotn) % 26 + 'a'; - else if (isalpha(buf[i])) + else if ('A' <= buf[i] && buf[i] <= 'Z') buf[i] = ((buf[i] - 'A') + rotn) % 26 + 'A'; } } @@ -335,9 +337,9 @@ rotn_customize(WT_ENCRYPTOR *encryptor, WT_SESSION *session, goto err; } for (i = 0; i < len; i++) { - if (islower(secret.str[i])) + if ('a' <= secret.str[i] && secret.str[i] <= 'z') base = 'a'; - else if (isupper(secret.str[i])) + else if ('A' <= secret.str[i] && secret.str[i] <= 'Z') base = 'A'; else { ret = EINVAL; |