summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-03-02 14:25:06 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-03-02 14:25:06 +0100
commit84413b1fe3811b2d07e0be4602c817580a3e4e92 (patch)
tree2595bff6fce049b6c54792be8fc094c3d1ea0e33 /src
parent65af86308981328697bbf06b0818dd4e4f8dfc58 (diff)
downloadfastd-84413b1fe3811b2d07e0be4602c817580a3e4e92.tar
fastd-84413b1fe3811b2d07e0be4602c817580a3e4e92.zip
Print error message on aborts due to buffer push/pull errors
Diffstat (limited to 'src')
-rw-r--r--src/fastd.c2
-rw-r--r--src/fastd.h8
-rw-r--r--src/method_aes128_gcm.c12
-rw-r--r--src/method_xsalsa20_poly1305.c10
4 files changed, 16 insertions, 16 deletions
diff --git a/src/fastd.c b/src/fastd.c
index f6a65e4..d43784f 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -793,7 +793,7 @@ static void handle_socket(fastd_context_t *ctx, fastd_socket_t *sock) {
fastd_peer_address_simplify(&recvaddr);
- fastd_buffer_push_head(&buffer, 1);
+ fastd_buffer_push_head(ctx, &buffer, 1);
fastd_peer_t *peer = NULL;
diff --git a/src/fastd.h b/src/fastd.h
index 880b6f0..703e463 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -385,17 +385,17 @@ static inline void fastd_buffer_free(fastd_buffer_t buffer) {
free(buffer.base);
}
-static inline void fastd_buffer_pull_head(fastd_buffer_t *buffer, size_t len) {
+static inline void fastd_buffer_pull_head(const fastd_context_t *ctx, fastd_buffer_t *buffer, size_t len) {
buffer->data -= len;
buffer->len += len;
if (buffer->data < buffer->base)
- abort();
+ exit_bug(ctx, "tried to pull buffer across head");
}
-static inline void fastd_buffer_push_head(fastd_buffer_t *buffer, size_t len) {
+static inline void fastd_buffer_push_head(const fastd_context_t *ctx, fastd_buffer_t *buffer, size_t len) {
if (buffer->len < len)
- abort();
+ exit_bug(ctx, "tried to push buffer across tail");
buffer->data += len;
buffer->len -= len;
diff --git a/src/method_aes128_gcm.c b/src/method_aes128_gcm.c
index 867e873..81edd7c 100644
--- a/src/method_aes128_gcm.c
+++ b/src/method_aes128_gcm.c
@@ -165,7 +165,7 @@ static inline void put_size(fastd_block128_t *out, size_t len) {
}
static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
- fastd_buffer_pull_head(&in, sizeof(fastd_block128_t));
+ fastd_buffer_pull_head(ctx, &in, sizeof(fastd_block128_t));
memset(in.data, 0, sizeof(fastd_block128_t));
size_t tail_len = alignto(in.len, sizeof(fastd_block128_t))-in.len;
@@ -198,7 +198,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
if (!ok) {
/* restore original buffer */
- fastd_buffer_push_head(&in, sizeof(fastd_block128_t));
+ fastd_buffer_push_head(ctx, &in, sizeof(fastd_block128_t));
fastd_buffer_free(*out);
return false;
}
@@ -207,7 +207,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
fastd_buffer_free(in);
- fastd_buffer_pull_head(out, NONCEBYTES);
+ fastd_buffer_pull_head(ctx, out, NONCEBYTES);
memcpy(out->data, session->send_nonce, NONCEBYTES);
increment_nonce(session->send_nonce);
@@ -238,7 +238,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
return false;
}
- fastd_buffer_push_head(&in, NONCEBYTES);
+ fastd_buffer_push_head(ctx, &in, NONCEBYTES);
size_t tail_len = alignto(in.len, sizeof(fastd_block128_t))-in.len;
*out = fastd_buffer_alloc(ctx, in.len, 0, tail_len);
@@ -264,14 +264,14 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
fastd_buffer_free(*out);
/* restore input buffer */
- fastd_buffer_pull_head(&in, NONCEBYTES);
+ fastd_buffer_pull_head(ctx, &in, NONCEBYTES);
return false;
}
fastd_buffer_free(in);
- fastd_buffer_push_head(out, sizeof(fastd_block128_t));
+ fastd_buffer_push_head(ctx, out, sizeof(fastd_block128_t));
if (age < 0) {
session->receive_reorder_seen >>= age;
diff --git a/src/method_xsalsa20_poly1305.c b/src/method_xsalsa20_poly1305.c
index 4cadca9..2de5c2b 100644
--- a/src/method_xsalsa20_poly1305.c
+++ b/src/method_xsalsa20_poly1305.c
@@ -137,7 +137,7 @@ static void method_session_free(fastd_context_t *ctx, fastd_method_session_state
}
static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_method_session_state_t *session, fastd_buffer_t *out, fastd_buffer_t in) {
- fastd_buffer_pull_head(&in, crypto_secretbox_xsalsa20poly1305_ZEROBYTES);
+ fastd_buffer_pull_head(ctx, &in, crypto_secretbox_xsalsa20poly1305_ZEROBYTES);
memset(in.data, 0, crypto_secretbox_xsalsa20poly1305_ZEROBYTES);
*out = fastd_buffer_alloc(ctx, in.len, 0, 0);
@@ -150,7 +150,7 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
fastd_buffer_free(in);
- fastd_buffer_push_head(out, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES-NONCEBYTES);
+ fastd_buffer_push_head(ctx, out, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES-NONCEBYTES);
memcpy(out->data, session->send_nonce, NONCEBYTES);
increment_nonce(session->send_nonce);
@@ -181,7 +181,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
return false;
}
- fastd_buffer_pull_head(&in, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES-NONCEBYTES);
+ fastd_buffer_pull_head(ctx, &in, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES-NONCEBYTES);
memset(in.data, 0, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES);
*out = fastd_buffer_alloc(ctx, in.len, 0, 0);
@@ -190,7 +190,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
fastd_buffer_free(*out);
/* restore input buffer */
- fastd_buffer_push_head(&in, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES-NONCEBYTES);
+ fastd_buffer_push_head(ctx, &in, crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES-NONCEBYTES);
memcpy(in.data, nonce, NONCEBYTES);
return false;
}
@@ -213,7 +213,7 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho
session->receive_reorder_seen |= (1 << (age-1));
}
- fastd_buffer_push_head(out, crypto_secretbox_xsalsa20poly1305_ZEROBYTES);
+ fastd_buffer_push_head(ctx, out, crypto_secretbox_xsalsa20poly1305_ZEROBYTES);
return true;
}