From 8959897d6b1b89d8a5e9bd2567b5472112b45f7d Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Sun, 8 Aug 2021 11:23:02 +0800 Subject: [PATCH] determine scanf return value. --- src/kit/shell/src/shellDarwin.c | 4 +++- src/kit/shell/src/shellLinux.c | 4 +++- src/kit/shell/src/shellWindows.c | 4 +++- src/kit/taosdemo/taosdemo.c | 4 +++- src/kit/taosdump/taosdump.c | 4 +++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/kit/shell/src/shellDarwin.c b/src/kit/shell/src/shellDarwin.c index 49be3917a1..5ca4537aeb 100644 --- a/src/kit/shell/src/shellDarwin.c +++ b/src/kit/shell/src/shellDarwin.c @@ -86,7 +86,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { printf(DARWINCLIENT_VERSION, tsOsName, taos_get_client_info()); if (strlen(argv[i]) == 2) { printf("Enter password: "); - scanf("%s", g_password); + if (scanf("%s", g_password) > 1) { + fprintf(stderr, "password read error\n"); + } getchar(); } else { tstrncpy(g_password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE); diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index df01669841..d051d3535e 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -170,7 +170,9 @@ static void parse_password( printf(LINUXCLIENT_VERSION, tsOsName, taos_get_client_info()); if (strlen(argv[i]) == 2) { printf("Enter password: "); - scanf("%s", g_password); + if (scanf("%20s", g_password) > 1) { + fprintf(stderr, "password reading error\n"); + } getchar(); } else { tstrncpy(g_password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE); diff --git a/src/kit/shell/src/shellWindows.c b/src/kit/shell/src/shellWindows.c index 26aa632f04..bf9afe4b80 100644 --- a/src/kit/shell/src/shellWindows.c +++ b/src/kit/shell/src/shellWindows.c @@ -84,7 +84,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { printf(WINCLIENT_VERSION, tsOsName, taos_get_client_info()); if (strlen(argv[i]) == 2) { printf("Enter password: "); - scanf("%s", g_password); + if (scanf("%s", g_password) > 1) { + fprintf(stderr, "password read error!\n"); + } getchar(); } else { tstrncpy(g_password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE); diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index b6c3a00401..0a2b1d181a 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -863,7 +863,9 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { } else if (strncmp(argv[i], "-p", 2) == 0) { if (strlen(argv[i]) == 2) { printf("Enter password:"); - scanf("%s", arguments->password); + if (scanf("%s", arguments->password) > 1) { + fprintf(stderr, "password read error!\n"); + } } else { tstrncpy(arguments->password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE); } diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 705e7d361b..b7073c28a7 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -561,7 +561,9 @@ static void parse_password( if (strncmp(argv[i], "-p", 2) == 0) { if (strlen(argv[i]) == 2) { printf("Enter password: "); - scanf("%s", arguments->password); + if(scanf("%20s", arguments->password) > 1) { + errorPrint("%s() LN%d, password read error!\n", __func__, __LINE__); + } } else { tstrncpy(arguments->password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE); } -- GitLab