Commit 65e96579 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

shrpx: Replace strncpy + putting null with memcpy in ssl_pem_passwd_cb

parent 06220f7f
...@@ -91,8 +91,8 @@ void set_npn_prefs(unsigned char *out, const char **protos, size_t len) ...@@ -91,8 +91,8 @@ void set_npn_prefs(unsigned char *out, const char **protos, size_t len)
} }
} // namespace } // namespace
namespace {
static int ssl_pem_passwd_cb(char *buf, int size, int rwflag, void *user_data) int ssl_pem_passwd_cb(char *buf, int size, int rwflag, void *user_data)
{ {
Config *config = (Config *)user_data; Config *config = (Config *)user_data;
int len = (int)strlen(config->private_key_passwd); int len = (int)strlen(config->private_key_passwd);
...@@ -100,12 +100,11 @@ static int ssl_pem_passwd_cb(char *buf, int size, int rwflag, void *user_data) ...@@ -100,12 +100,11 @@ static int ssl_pem_passwd_cb(char *buf, int size, int rwflag, void *user_data)
LOG(ERROR) << "ssl_pem_passwd_cb: buf is too small " << size; LOG(ERROR) << "ssl_pem_passwd_cb: buf is too small " << size;
return 0; return 0;
} }
// Copy string including last '\0'.
strncpy(buf, config->private_key_passwd, len); memcpy(buf, config->private_key_passwd, len+1);
buf[len] = '\0';
return len; return len;
} }
} // namespace
SSL_CTX* create_ssl_context() SSL_CTX* create_ssl_context()
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment