Skip to content

Commit b8468d1

Browse files
committed
extmod/modwebrepl: Get rid of using strncpy().
1 parent c6923f5 commit b8468d1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

extmod/modwebrepl.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,11 @@ STATIC mp_uint_t webrepl_write(mp_obj_t self_in, const void *buf, mp_uint_t size
285285
}
286286

287287
STATIC mp_obj_t webrepl_set_password(mp_obj_t passwd_in) {
288-
const char *passwd = mp_obj_str_get_str(passwd_in);
289-
strncpy(webrepl_passwd, passwd, sizeof(webrepl_passwd));
288+
mp_uint_t len;
289+
const char *passwd = mp_obj_str_get_data(passwd_in, &len);
290+
len = MIN(len, sizeof(webrepl_passwd) - 1);
291+
memcpy(webrepl_passwd, passwd, len);
292+
webrepl_passwd[len] = 0;
290293
return mp_const_none;
291294
}
292295
STATIC MP_DEFINE_CONST_FUN_OBJ_1(webrepl_set_password_obj, webrepl_set_password);

0 commit comments

Comments
 (0)