diff options
author | tb <> | 2018-08-14 17:51:36 +0000 |
---|---|---|
committer | tb <> | 2018-08-14 17:51:36 +0000 |
commit | 6f67f5587af65f7420834c04188f5ead57ab95f1 (patch) | |
tree | 09d5abfb98feb767117683f1e4d667977cbf1f49 | |
parent | 8632dd05c9defdc3ad6ac7ac3bcde039dbf92a2c (diff) | |
download | openbsd-6f67f5587af65f7420834c04188f5ead57ab95f1.tar.gz openbsd-6f67f5587af65f7420834c04188f5ead57ab95f1.tar.bz2 openbsd-6f67f5587af65f7420834c04188f5ead57ab95f1.zip |
The UI_add_{input,verify}_string() functions want a length not including
the terminating NUL. EVP_read_pw_string_min() got this wrong, leading to
a one-byte buffer overrun in all callers of EVP_read_pw_string().
Found by mestre running 'openssl passwd' with MALLOC_OPTIONS including C.
Fix this by doing some basic sanity checking in EVP_read_pw_string_min().
Cap the len argument at BUFSIZ and ensure that min < len as well as
0 <= min and 1 <= len. The last two checks are important as these
numbers may end up in reallocarray().
ok bcook (on previous version), jsing, mestre
-rw-r--r-- | src/lib/libcrypto/evp/evp_key.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c index 33de513ef2..debd1b7561 100644 --- a/src/lib/libcrypto/evp/evp_key.c +++ b/src/lib/libcrypto/evp/evp_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp_key.c,v 1.24 2017/01/29 17:49:23 beck Exp $ */ | 1 | /* $OpenBSD: evp_key.c,v 1.25 2018/08/14 17:51:36 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -101,17 +101,20 @@ EVP_read_pw_string_min(char *buf, int min, int len, const char *prompt, | |||
101 | char buff[BUFSIZ]; | 101 | char buff[BUFSIZ]; |
102 | UI *ui; | 102 | UI *ui; |
103 | 103 | ||
104 | if (len > BUFSIZ) | ||
105 | len = BUFSIZ; | ||
106 | if (min < 0 || len - 1 < min) | ||
107 | return -1; | ||
104 | if ((prompt == NULL) && (prompt_string[0] != '\0')) | 108 | if ((prompt == NULL) && (prompt_string[0] != '\0')) |
105 | prompt = prompt_string; | 109 | prompt = prompt_string; |
106 | ui = UI_new(); | 110 | ui = UI_new(); |
107 | if (ui == NULL) | 111 | if (ui == NULL) |
108 | return -1; | 112 | return -1; |
109 | if (UI_add_input_string(ui, prompt, 0, buf, min, | 113 | if (UI_add_input_string(ui, prompt, 0, buf, min, len - 1) < 0) |
110 | (len >= BUFSIZ) ? BUFSIZ - 1 : len) < 0) | ||
111 | return -1; | 114 | return -1; |
112 | if (verify) { | 115 | if (verify) { |
113 | if (UI_add_verify_string(ui, prompt, 0, buff, min, | 116 | if (UI_add_verify_string(ui, prompt, 0, buff, min, len - 1, buf) |
114 | (len >= BUFSIZ) ? BUFSIZ - 1 : len, buf) < 0) | 117 | < 0) |
115 | return -1; | 118 | return -1; |
116 | } | 119 | } |
117 | ret = UI_process(ui); | 120 | ret = UI_process(ui); |