Browse Source

Line with spaces only is not legal command

Serj Kalichev 5 months ago
parent
commit
1b56ef3809
1 changed files with 20 additions and 1 deletions
  1. 20 1
      klish/ktp/ktpd_session.c

+ 20 - 1
klish/ktp/ktpd_session.c

@@ -13,6 +13,7 @@
 #include <syslog.h>
 #include <poll.h>
 #include <sys/wait.h>
+#include <ctype.h>
 
 #include <faux/str.h>
 #include <faux/conv.h>
@@ -338,6 +339,23 @@ static bool_t ktpd_session_process_auth(ktpd_session_t *ktpd, faux_msg_t *msg)
 }
 
 
+static bool_t line_has_content(const char *line)
+{
+	const char *l = line;
+
+	if (faux_str_is_empty(line))
+		return BOOL_FALSE;
+
+	while (*l) {
+		if (!isspace(*l))
+			return BOOL_TRUE;
+		l++;
+	}
+
+	return BOOL_FALSE;
+}
+
+
 static bool_t ktpd_session_process_cmd(ktpd_session_t *ktpd, faux_msg_t *msg)
 {
 	char *line = NULL;
@@ -357,7 +375,8 @@ static bool_t ktpd_session_process_cmd(ktpd_session_t *ktpd, faux_msg_t *msg)
 
 	// Get line from message
 	line = faux_msg_get_str_param_by_type(msg, KTP_PARAM_LINE);
-	if (faux_str_is_empty(line)) {
+	if (!line_has_content(line)) {
+		faux_str_free(line);
 		// Line is not specified. User sent empty command.
 		// It's not bug. Send OK to user and regenerate prompt
 		ack = ktp_msg_preform(cmd, KTP_STATUS_NONE);