From b8468d12a1a35eececff6432349dc0f66b10d3dd Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 2 May 2016 20:52:34 +0300 Subject: [PATCH] extmod/modwebrepl: Get rid of using strncpy(). --- extmod/modwebrepl.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/extmod/modwebrepl.c b/extmod/modwebrepl.c index 2646708059..c160abea2f 100644 --- a/extmod/modwebrepl.c +++ b/extmod/modwebrepl.c @@ -285,8 +285,11 @@ STATIC mp_uint_t webrepl_write(mp_obj_t self_in, const void *buf, mp_uint_t size } STATIC mp_obj_t webrepl_set_password(mp_obj_t passwd_in) { - const char *passwd = mp_obj_str_get_str(passwd_in); - strncpy(webrepl_passwd, passwd, sizeof(webrepl_passwd)); + mp_uint_t len; + const char *passwd = mp_obj_str_get_data(passwd_in, &len); + len = MIN(len, sizeof(webrepl_passwd) - 1); + memcpy(webrepl_passwd, passwd, len); + webrepl_passwd[len] = 0; return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(webrepl_set_password_obj, webrepl_set_password);