diff --git a/libs/esl/fs_cli.c b/libs/esl/fs_cli.c index fd6153e091..b63fdd845a 100644 --- a/libs/esl/fs_cli.c +++ b/libs/esl/fs_cli.c @@ -1002,10 +1002,13 @@ static const char *basic_gets(int *cnt) for (x = 0; x < (sizeof(command_buf) - 1); x++) { int c = getchar(); if (c < 0) { + size_t command_buf_len; if (fgets(command_buf, sizeof(command_buf) - 1, stdin) != command_buf) { break; + } + if ((command_buf_len = strlen(command_buf)) > 0) { + command_buf[command_buf_len - 1] = '\0'; /* remove endline */ } - command_buf[strlen(command_buf)-1] = '\0'; /* remove endline */ break; } command_buf[x] = (char) c;