]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge remote-tracking branch 'refs/remotes/fml/master'
authorAndre Noll <maan@systemlinux.org>
Thu, 3 Mar 2011 18:43:25 +0000 (19:43 +0100)
committerAndre Noll <maan@systemlinux.org>
Thu, 3 Mar 2011 18:43:25 +0000 (19:43 +0100)
command.c
crypt.c
para.h
score.c

index f462016b2e572f6a58691362cb52c9bdb280ea91..f9ef6cd75ab8733408d3c2542230ae806281bf85 100644 (file)
--- a/command.c
+++ b/command.c
@@ -743,24 +743,24 @@ __noreturn void handle_connect(int fd, const char *peername)
        /* we need a blocking fd here as recv() might return EAGAIN otherwise. */
        ret = mark_fd_blocking(fd);
        if (ret < 0)
-               goto err_out;
+               goto net_err;
        /* send Welcome message */
        ret = send_va_buffer(fd, "This is para_server, version "
                PACKAGE_VERSION  ".\n" );
        if (ret < 0)
-               goto err_out;
+               goto net_err;
        /* recv auth request line */
        ret = recv_buffer(fd, buf, sizeof(buf));
        if (ret < 0)
-               goto err_out;
+               goto net_err;
        if (ret < 10) {
                ret = -E_AUTH_REQUEST;
-               goto err_out;
+               goto net_err;
        }
        numbytes = ret;
        ret = -E_AUTH_REQUEST;
        if (strncmp(buf, AUTH_REQUEST_MSG, strlen(AUTH_REQUEST_MSG)))
-               goto err_out;
+               goto net_err;
        p = buf + strlen(AUTH_REQUEST_MSG);
        PARA_DEBUG_LOG("received auth request for user %s\n", p);
        ret = -E_BAD_USER;
@@ -770,7 +770,7 @@ __noreturn void handle_connect(int fd, const char *peername)
                ret = para_encrypt_buffer(u->rsa, rand_buf, sizeof(rand_buf),
                        (unsigned char *)buf);
                if (ret < 0)
-                       goto err_out;
+                       goto net_err;
                numbytes = ret;
        } else {
                /*
diff --git a/crypt.c b/crypt.c
index 917948c6185710fb828b441025b8d46a0fdc2924..cdcb6149d04254a0def3bcc903823f71ae3a89e5 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -203,6 +203,8 @@ int para_encrypt_buffer(RSA *rsa, unsigned char *inbuf,
        return ret < 0? -E_ENCRYPT : ret;
 }
 
+#define RC4_ALIGN 8
+
 /**
  * Encrypt and send a buffer.
  *
@@ -218,10 +220,16 @@ int rc4_send_bin_buffer(struct rc4_context *rc4c, const char *buf, size_t len)
 {
        int ret;
        unsigned char *tmp;
+       static unsigned char remainder[RC4_ALIGN];
+       size_t l1 = ROUND_DOWN(len, RC4_ALIGN), l2 = ROUND_UP(len, RC4_ALIGN);
 
        assert(len);
-       tmp = para_malloc(len + 8);
-       RC4(&rc4c->send_key, len, (const unsigned char *)buf, tmp);
+       tmp = para_malloc(l2);
+       RC4(&rc4c->send_key, l1, (const unsigned char *)buf, tmp);
+       if (len > l1) {
+               memcpy(remainder, buf + l1, len - l1);
+               RC4(&rc4c->send_key, len - l1, remainder, tmp + l1);
+       }
        ret = write_all(rc4c->fd, (char *)tmp, &len);
        free(tmp);
        return ret;
diff --git a/para.h b/para.h
index c5e12fe6da3ef864bdc16bb0eaa178a8b5965cee..f095a6aa385d2f717048f1e25e15741a15632617 100644 (file)
--- a/para.h
+++ b/para.h
@@ -165,6 +165,16 @@ _static_inline_ long int para_random(unsigned max)
        return ((max + 0.0) * (random() / (RAND_MAX + 1.0)));
 }
 
+/** Round up x to next multiple of y. */
+#define ROUND_UP(x, y) ({ \
+       const typeof(y) _divisor = y; \
+       ((x) + _divisor - 1) / _divisor * _divisor; })
+
+/** Round down x to multiple of y. */
+#define ROUND_DOWN(x, y) ({ \
+       const typeof(y) _divisor = y; \
+       (x) / _divisor * _divisor; })
+
 /** Divide and round up to next integer. */
 #define DIV_ROUND_UP(x, y) ({ \
        typeof(y) _divisor = y; \
diff --git a/score.c b/score.c
index 27fec711047f230c96215be2d90def9db3320bbe..f5fe4a833f6f6f99ca3d9afca49175113b1eac78 100644 (file)
--- a/score.c
+++ b/score.c
@@ -38,8 +38,8 @@ static int ptr_compare(const struct osl_object *obj1, const struct osl_object *o
  */
 static int score_compare(const struct osl_object *obj1, const struct osl_object *obj2)
 {
-       int d1 = *(int*)obj1->data;
-       int d2 = *(int*)obj2->data;
+       long d1 = *(long *)obj1->data;
+       long d2 = *(long *)obj2->data;
        int ret = NUM_COMPARE(d2, d1);
 
        if (ret)
@@ -141,7 +141,7 @@ int score_add(const struct osl_row *aft_row, long score)
        size = score_table_desc.column_descriptions[SCORECOL_SCORE].data_size;
        score_objs[SCORECOL_SCORE].data = para_malloc(size);
        score_objs[SCORECOL_SCORE].size = size;
-       *(int *)(score_objs[SCORECOL_SCORE].data) = score;
+       *(long *)(score_objs[SCORECOL_SCORE].data) = score;
 
 //     PARA_DEBUG_LOG("adding %p\n", *(void **) (score_objs[SCORECOL_AFT_ROW].data));
        ret = osl(osl_add_row(score_table, score_objs));