summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorarmink <[email protected]>2016-11-26 16:45:54 +0800
committerarmink <[email protected]>2016-11-26 16:45:54 +0800
commit72e4efb46ee6a395f27ff54a64d3daaf24d85187 (patch)
tree3f476bd0bb780a4d12d8584826b95aef8e8e5f35 /components
parent8ff75290391c02e92a9b3510b72c1495da25cd13 (diff)
[finsh]Improve the set password.
Diffstat (limited to 'components')
-rw-r--r--components/finsh/shell.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/components/finsh/shell.c b/components/finsh/shell.c
index 83709560b1..7e8a84ab27 100644
--- a/components/finsh/shell.c
+++ b/components/finsh/shell.c
@@ -33,6 +33,7 @@
* 2010-04-01 Bernard add prompt output when start and remove the empty history
* 2011-02-23 Bernard fix variable section end issue of finsh shell
* initialization when use GNU GCC compiler.
+ * 2016-11-26 armink add password authentication
*/
#include <rthw.h>
@@ -180,12 +181,14 @@ rt_uint32_t finsh_get_echo()
*
* @param password new password
*
- * @return result, RT_EOK on OK, -RT_ERROR on the new password length is less than FINSH_PASSWORD_MIN
+ * @return result, RT_EOK on OK, -RT_ERROR on the new password length is less than
+ * FINSH_PASSWORD_MIN or greater than FINSH_PASSWORD_MAX
*/
rt_err_t finsh_set_password(const char *password) {
rt_ubase_t level;
+ rt_size_t pw_len = rt_strlen(password);
- if (rt_strlen(password) < FINSH_PASSWORD_MIN)
+ if (pw_len < FINSH_PASSWORD_MIN || pw_len > FINSH_PASSWORD_MAX)
return -RT_ERROR;
level = rt_hw_interrupt_disable();
@@ -407,7 +410,7 @@ void finsh_thread_entry(void *parameter)
#ifdef FINSH_USING_AUTH
/* set the default password when the password isn't setting */
if (rt_strlen(finsh_get_password()) == 0)
- finsh_set_password(FINSH_DEFAULT_PASSWORD);
+ RT_ASSERT(finsh_set_password(FINSH_DEFAULT_PASSWORD) == RT_EOK);
/* waiting authenticate success */
finsh_wait_auth();
#endif