]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Handle empty command lines properly.
authorAndre Noll <maan@systemlinux.org>
Sat, 22 Jun 2013 14:59:04 +0000 (16:59 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 22 Jun 2013 14:59:04 +0000 (16:59 +0200)
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.

audioc.c
audiod_command.c
client.c

index b2c6786a6573ba2636606cde09403e38a590e0c6..be67ebda8a8574681fbb21670039fe333137f266 100644 (file)
--- 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)
index 2f3726faed46a8d004d4111a9e503a70851af511..b49d659e0ac0bd784b2002b941b3471540ee5ac9 100644 (file)
@@ -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);
index c47dafe8afd300183c8d3853f9da7e0198b4c88d..8657b3aa3cdd5e3c24f2ede17afe3c9ac300e08e 100644 (file)
--- 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)