From: Andre Noll <maan@systemlinux.org>
Date: Sat, 22 Jun 2013 14:59:04 +0000 (+0200)
Subject: Handle empty command lines properly.
X-Git-Tag: v0.4.13~25
X-Git-Url: https://git.tue.mpg.de/?a=commitdiff_plain;h=bb5101625c76c3bfa5fe516e6e669a43108ff597;p=paraslash.git

Handle empty command lines properly.

Both para_client and para_audioc create an argument vector from the
given command line using create_argv(). If the command line contains
only whitespace characters, this vector has length zero, and argv[0]
is NULL.

We missed to check for this at at least three places in audioc.c,
client.c and audiod_command.c, which resulted in crashes due to NULL
pointer dereferences or failed assertions.

These bugs can easily be triggered by starting para_client or
para_audioc in interactive mode, entering a single space character
and hitting return.

This patch adds the missing checks to prevent the crashes.
---

diff --git a/audioc.c b/audioc.c
index b2c6786a..be67ebda 100644
--- a/audioc.c
+++ b/audioc.c
@@ -173,6 +173,8 @@ static int audioc_i9e_line_handler(char *line)
 	conf.inputs_num = ret;
 	args = concat_args(conf.inputs_num, conf.inputs);
 	free_argv(conf.inputs);
+	if (!args)
+		return 0;
 	conf.inputs_num = 0; /* required for audioc_cmdline_parser_free() */
 	ret = connect_audiod(socket_name, args);
 	if (ret < 0)
diff --git a/audiod_command.c b/audiod_command.c
index 2f3726fa..b49d659e 100644
--- a/audiod_command.c
+++ b/audiod_command.c
@@ -442,7 +442,7 @@ int handle_connect(int accept_fd, fd_set *rfds)
 	if (ret < 0)
 		goto out;
 	ret = create_argv(buf, "\n", &argv);
-	if (ret < 0)
+	if (ret <= 0)
 		goto out;
 	argc = ret;
 	//PARA_INFO_LOG("argv[0]: %s, argc = %d\n", argv[0], argc);
diff --git a/client.c b/client.c
index c47dafe8..8657b3aa 100644
--- a/client.c
+++ b/client.c
@@ -447,7 +447,7 @@ static int client_i9e_line_handler(char *line)
 	client_disconnect(ct);
 	PARA_DEBUG_LOG("line: %s\n", line);
 	ret = make_client_argv(line);
-	if (ret < 0)
+	if (ret <= 0)
 		return ret;
 	ret = client_connect(ct, &sched, NULL, NULL);
 	if (ret < 0)