From 9cfc17a210aa1b1fc5ce5dcbffb5783ba1289892 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 1 Jun 2016 05:07:55 +0000 Subject: crypt_r.c: fix out of bounds access * missing/crypt_r.c (a64toi): initialize statically and fix out of bounds access when salt is not 7bit clean. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55243 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ missing/crypt_r.c | 26 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index ae5468056d..4248afa516 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jun 1 14:07:53 2016 Nobuyoshi Nakada + + * missing/crypt_r.c (a64toi): initialize statically and fix out of + bounds access when salt is not 7bit clean. + Wed Jun 1 11:34:59 2016 NAKAMURA Usaku * win32/Makefile.sub (MISSING): fixed build error introduced at r55237. diff --git a/missing/crypt_r.c b/missing/crypt_r.c index a622725b3f..d5a16ac57a 100644 --- a/missing/crypt_r.c +++ b/missing/crypt_r.c @@ -289,12 +289,25 @@ static const unsigned char CIFP[] = { /* compressed/interleaved permutation */ static const unsigned char itoa64[] = /* 0..63 => ascii-64 */ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +/* table that converts chars "./0-9A-Za-z"to integers 0-63. */ +static const unsigned char a64toi[256] = { +#define A64TOI1(c) \ + ((c) == '.' ? 0 : \ + (c) == '/' ? 1 : \ + ('0' <= (c) && (c) <= '9') ? (c) - '0' + 2 : \ + ('A' <= (c) && (c) <= 'Z') ? (c) - 'A' + 12 : \ + ('a' <= (c) && (c) <= 'z') ? (c) - 'a' + 38 : \ + 0) +#define A64TOI4(base) A64TOI1(base+0), A64TOI1(base+1), A64TOI1(base+2), A64TOI1(base+3) +#define A64TOI16(base) A64TOI4(base+0), A64TOI4(base+4), A64TOI4(base+8), A64TOI4(base+12) +#define A64TOI64(base) A64TOI16(base+0x00), A64TOI16(base+0x10), A64TOI16(base+0x20), A64TOI16(base+0x30) + A64TOI64(0x00), A64TOI64(0x40), + A64TOI64(0x00), A64TOI64(0x40), +}; + /* ===== Tables that are initialized at run time ==================== */ typedef struct { - /* table that converts chars "./0-9A-Za-z"to integers 0-63. */ - unsigned char a64toi[128]; - /* Initial key schedule permutation */ C_block PC1ROT[64/CHUNKBITS][1<a64toi) #define PC1ROT (des_tables->PC1ROT) #define PC2ROT (des_tables->PC2ROT) #define IE3264 (des_tables->IE3264) @@ -602,12 +614,6 @@ init_des(void) if (des_tables->ready) return; - /* - * table that converts chars "./0-9A-Za-z"to integers 0-63. - */ - for (i = 0; i < 64; i++) - a64toi[itoa64[i]] = i; - /* * PC1ROT - bit reverse, then PC1, then Rotate, then PC2. */ -- cgit v1.2.3