diff options
author | Doug Hogan <[email protected]> | 2019-01-05 13:40:58 -0800 |
---|---|---|
committer | Doug Hogan <[email protected]> | 2019-01-08 01:11:59 -0800 |
commit | 89d0f344ae30864a626a3af9db7953af8f38f499 (patch) | |
tree | c19f3e445f5794584173a95db10d64145f2f9182 /lib/crypto | |
parent | 5f8f5ea331fac053ae6ffeaa50dc3cf816cc3074 (diff) | |
download | otp-89d0f344ae30864a626a3af9db7953af8f38f499.tar.gz otp-89d0f344ae30864a626a3af9db7953af8f38f499.tar.bz2 otp-89d0f344ae30864a626a3af9db7953af8f38f499.zip |
Revamp pem_passwd_cb_fun()
Diffstat (limited to 'lib/crypto')
-rw-r--r-- | lib/crypto/c_src/otp_test_engine.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/crypto/c_src/otp_test_engine.c b/lib/crypto/c_src/otp_test_engine.c index 3b228b8663..d0d4f7741d 100644 --- a/lib/crypto/c_src/otp_test_engine.c +++ b/lib/crypto/c_src/otp_test_engine.c @@ -21,8 +21,10 @@ #ifdef _WIN32 #define OPENSSL_OPT_WINDLL #endif + #include <stdio.h> #include <string.h> +#include <limits.h> #include <openssl/md5.h> #include <openssl/rsa.h> @@ -344,23 +346,28 @@ EVP_PKEY* test_key_load(ENGINE *eng, const char *id, UI_METHOD *ui_method, void int pem_passwd_cb_fun(char *buf, int size, int rwflag, void *password) { - int i; + size_t i; + + if (size < 0) + return 0; fprintf(stderr, "In pem_passwd_cb_fun\r\n"); if (!password) return 0; i = strlen(password); - if (i < size) { - /* whole pwd (incl terminating 0) fits */ - fprintf(stderr, "Got FULL pwd %d(%d) chars\r\n", i, size); - memcpy(buf, (char*)password, i+1); - return i+1; - } else { - fprintf(stderr, "Got TO LONG pwd %d(%d) chars\r\n", i, size); - /* meaningless with a truncated password */ - return 0; - } + if (i >= (size_t)size || i > INT_MAX - 1) + goto err; + + /* whole pwd (incl terminating 0) fits */ + fprintf(stderr, "Got FULL pwd %zu(%d) chars\r\n", i, size); + memcpy(buf, (char*)password, i+1); + return (int)i+1; + + err: + fprintf(stderr, "Got TO LONG pwd %zu(%d) chars\r\n", i, size); + /* meaningless with a truncated password */ + return 0; } #endif |