]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
server/gcrypt: Fix sending the empty status items.
authorAndre Noll <maan@systemlinux.org>
Mon, 29 Jul 2013 22:44:37 +0000 (00:44 +0200)
committerAndre Noll <maan@systemlinux.org>
Wed, 31 Jul 2013 21:17:12 +0000 (23:17 +0200)
When para_server enters the "stopped" state, it needs to inform all
clients which are executing the stat command that no audio file is
currently available.

To this aim the stat command handler calls empty_status_items(), which
creates a buffer containing empty values for most status items. This
function tries to be smart by computing the buffer only once. It
saves a reference in a static variable so that on subsequent calls
it can simply return the same buffer.

This works fine when para_server is compiled against the openssl
crypto library. However, it fails when libgcrypt is used because with
libgcrypt the send buffer is encrypted in-place. Hence on subsequent
calls the already encrypted buffer will be encrypted again, resulting
in garbage being sent to the client.

This patch avoids this bug by using a fresh buffer each time the
empty status items are sent.

command.c

index 79ca3652040188010dbbf2209fbf8ffe5757db50..41a58eac0517e15e44c964250578173708289e60 100644 (file)
--- a/command.c
+++ b/command.c
@@ -474,11 +474,8 @@ static int com_version(struct command_context *cc)
  */
 static unsigned empty_status_items(int parser_friendly, char **result)
 {
-       static char *esi;
-       static unsigned len;
-
-       if (esi)
-               goto out;
+       char *esi;
+       unsigned len;
 
        if (parser_friendly)
                len = xasprintf(&esi,
@@ -498,7 +495,6 @@ static unsigned empty_status_items(int parser_friendly, char **result)
                        EMPTY_STATUS_ITEMS
                        #undef ITEM
                );
-out:
        *result = esi;
        return len;
 }
@@ -509,7 +505,7 @@ static int com_stat(struct command_context *cc)
 {
        int i, ret;
        struct misc_meta_data tmp, *nmmd = &tmp;
-       char *s, *esi = NULL;
+       char *s;
        int32_t num = 0;
        int parser_friendly = 0;
 
@@ -549,12 +545,15 @@ static int com_stat(struct command_context *cc)
                if (ret < 0)
                        goto out;
                if (nmmd->vss_status_flags & VSS_NEXT) {
+                       char *esi;
                        ret = empty_status_items(parser_friendly, &esi);
                        if (cc->use_sideband)
                                ret = send_sb(&cc->scc, esi, ret, SBD_OUTPUT,
-                                       true);
-                       else
+                                       false);
+                       else {
                                ret = sc_send_bin_buffer(&cc->scc, esi, ret);
+                               free(esi);
+                       }
                        if (ret < 0)
                                goto out;
                } else
@@ -568,7 +567,6 @@ static int com_stat(struct command_context *cc)
                        goto out;
        }
 out:
-       free(esi);
        return ret;
 }