aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2004-01-02 09:03:38 +0000
committerRoger Dingledine <arma@torproject.org>2004-01-02 09:03:38 +0000
commit53061b3778167a9c4968b12c6d60e43301af46b7 (patch)
tree6a0fa36cab54d2bef96c57da55e6701611c6de9d /src
parentc2e37901be4187bb209581bab31db0c305bb53cd (diff)
downloadtor-53061b3778167a9c4968b12c6d60e43301af46b7.tar
tor-53061b3778167a9c4968b12c6d60e43301af46b7.tar.gz
fix endian issue: rh.integrity was getting sent wrong
now it's a char[4] rather than an int svn:r966
Diffstat (limited to 'src')
-rw-r--r--src/or/circuit.c29
-rw-r--r--src/or/connection_edge.c4
-rw-r--r--src/or/or.h2
3 files changed, 19 insertions, 16 deletions
diff --git a/src/or/circuit.c b/src/or/circuit.c
index 22a17fa9a..071c94726 100644
--- a/src/or/circuit.c
+++ b/src/or/circuit.c
@@ -314,14 +314,15 @@ int circuit_stream_is_being_handled(connection_t *conn) {
/* update digest from the payload of cell. assign integrity part to cell. */
static void relay_set_digest(crypto_digest_env_t *digest, cell_t *cell) {
- uint32_t integrity;
+ char integrity[4];
relay_header_t rh;
crypto_digest_add_bytes(digest, cell->payload, CELL_PAYLOAD_SIZE);
- crypto_digest_get_digest(digest, (char *)&integrity, 4);
- log_fn(LOG_DEBUG,"Putting digest of %u into relay cell.",integrity);
+ crypto_digest_get_digest(digest, integrity, 4);
+ log_fn(LOG_DEBUG,"Putting digest of %u %u %u %u into relay cell.",
+ integrity[0], integrity[1], integrity[2], integrity[3]);
relay_header_unpack(&rh, cell->payload);
- rh.integrity = integrity;
+ memcpy(rh.integrity, integrity, 4);
relay_header_pack(cell->payload, &rh);
}
@@ -330,29 +331,31 @@ static void relay_set_digest(crypto_digest_env_t *digest, cell_t *cell) {
* and cell to their original state and return 0.
*/
static int relay_digest_matches(crypto_digest_env_t *digest, cell_t *cell) {
- uint32_t received_integrity, calculated_integrity;
+ char received_integrity[4], calculated_integrity[4];
relay_header_t rh;
crypto_digest_env_t *backup_digest=NULL;
backup_digest = crypto_digest_dup(digest);
relay_header_unpack(&rh, cell->payload);
- received_integrity = rh.integrity;
- rh.integrity = 0;
+ memcpy(received_integrity, rh.integrity, 4);
+ memset(rh.integrity, 0, 4);
relay_header_pack(cell->payload, &rh);
- log_fn(LOG_DEBUG,"Reading digest of %u from relay cell.",received_integrity);
+ log_fn(LOG_DEBUG,"Reading digest of %u %u %u %u from relay cell.",
+ received_integrity[0], received_integrity[1],
+ received_integrity[2], received_integrity[3]);
crypto_digest_add_bytes(digest, cell->payload, CELL_PAYLOAD_SIZE);
- crypto_digest_get_digest(digest, (char *)&calculated_integrity, 4);
+ crypto_digest_get_digest(digest, calculated_integrity, 4);
- if(received_integrity != calculated_integrity) {
- log_fn(LOG_INFO,"Recognized=0 but bad digest. Not recognizing. (%d vs %d).",
- received_integrity, calculated_integrity);
+ if(memcmp(received_integrity, calculated_integrity, 4)) {
+ log_fn(LOG_INFO,"Recognized=0 but bad digest. Not recognizing.");
+// (%d vs %d).", received_integrity, calculated_integrity);
/* restore digest to its old form */
crypto_digest_assign(digest, backup_digest);
/* restore the relay header */
- rh.integrity = received_integrity;
+ memcpy(rh.integrity, received_integrity, 4);
relay_header_pack(cell->payload, &rh);
crypto_free_digest_env(backup_digest);
return 0;
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 74de28c7d..d8c23d90c 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -24,7 +24,7 @@ void relay_header_pack(char *dest, const relay_header_t *src) {
*(uint8_t*)(dest) = src->command;
*(uint16_t*)(dest+1) = htons(src->recognized);
*(uint16_t*)(dest+3) = htons(src->stream_id);
- *(uint32_t*)(dest+5) = htonl(src->integrity);
+ memcpy(dest+5, src->integrity, 4);
*(uint16_t*)(dest+9) = htons(src->length);
}
@@ -32,7 +32,7 @@ void relay_header_unpack(relay_header_t *dest, const char *src) {
dest->command = *(uint8_t*)(src);
dest->recognized = ntohs(*(uint16_t*)(src+1));
dest->stream_id = ntohs(*(uint16_t*)(src+3));
- dest->integrity = ntohl(*(uint32_t*)(src+5));
+ memcpy(dest->integrity, src+5, 4);
dest->length = ntohs(*(uint16_t*)(src+9));
}
diff --git a/src/or/or.h b/src/or/or.h
index 572041267..42b89c3ba 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -283,7 +283,7 @@ typedef struct {
uint8_t command;
uint16_t recognized;
uint16_t stream_id;
- uint32_t integrity;
+ char integrity[4];
uint16_t length;
} relay_header_t;