fecdec_filter: Avoid potentially expensive pointer subtraction.
[paraslash.git] / client_common.c
index c1e23f7a53d228bde4b3c26149432a71029327ad..cf77acd81beda8b79c1df5b607626c57975b3506 100644 (file)
@@ -64,6 +64,7 @@ void client_close(struct client_task *ct)
                disable_crypt(ct->fd);
                close(ct->fd);
        }
+       free(ct->buf);
        free(ct->user);
        free(ct->config_file);
        free(ct->key_file);
@@ -190,15 +191,15 @@ static void client_post_select(struct sched *s, struct task *t)
                t->error = client_recv_buffer(ct);
                if (t->error < 0)
                        return;
-               if (t->error != 64) {
+               if (t->error < 64) {
                        t->error = -E_INVALID_CHALLENGE;
                        PARA_ERROR_LOG("received the following: %s\n", ct->buf);
                        return;
                }
-               PARA_INFO_LOG("<-- [challenge]\n");
+               PARA_INFO_LOG("<-- [challenge] (%d bytes)\n", t->error);
                /* decrypt challenge number */
                t->error = para_decrypt_challenge(ct->key_file, &ct->challenge_nr,
-                       (unsigned char *) ct->buf, 64);
+                       (unsigned char *) ct->buf, t->error);
                if (t->error > 0)
                        ct->status = CL_RECEIVED_CHALLENGE;
                return;
@@ -327,6 +328,7 @@ int client_open(int argc, char *argv[], struct client_task **ct_ptr,
        int ret;
        struct client_task *ct = para_calloc(sizeof(struct client_task));
 
+       ct->buf = para_malloc(CLIENT_BUFSIZE);
        *ct_ptr = ct;
        ct->fd = -1;
        ret = -E_CLIENT_SYNTAX;