chiark / gitweb /
site, transform: per-transform-instance max_start_pad
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 25 Jul 2013 17:30:53 +0000 (18:30 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 25 Jul 2013 17:30:53 +0000 (18:30 +0100)
Replicate the max_start_pad value from the transform interface into
the instance interface.

Use the instance's version in site.c.

While we're at it, add an assertion to confirm that the value of
max_start_pad passed to buffer_init doesn't overrun the buffer.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
secnet.h
site.c
transform-common.h
util.c

index 46aac5b..2ccf161 100644 (file)
--- a/secnet.h
+++ b/secnet.h
@@ -396,6 +396,7 @@ struct transform_inst_if {
     transform_apply_fn *forwards;
     transform_apply_fn *reverse;
     transform_destroyinstance_fn *destroy;
+    int32_t max_start_pad; /* same as from transform_if */
 };
 
 struct transform_if {
diff --git a/site.c b/site.c
index 2cb53f6..2ada372 100644 (file)
--- a/site.c
+++ b/site.c
@@ -757,7 +757,7 @@ static bool_t generate_msg5(struct site *st)
 
     BUF_ALLOC(&st->buffer,"site:MSG5");
     /* We are going to add four words to the message */
-    buffer_init(&st->buffer,st->transform->max_start_pad+(4*4));
+    buffer_init(&st->buffer,st->new_transform->max_start_pad+(4*4));
     /* Give the netlink code an opportunity to put its own stuff in the
        message (configuration information, etc.) */
     buf_prepend_uint32(&st->buffer,LABEL_MSG5);
@@ -804,7 +804,7 @@ static void create_msg6(struct site *st, struct transform_inst_if *transform,
 
     BUF_ALLOC(&st->buffer,"site:MSG6");
     /* We are going to add four words to the message */
-    buffer_init(&st->buffer,st->transform->max_start_pad+(4*4));
+    buffer_init(&st->buffer,transform->max_start_pad+(4*4));
     /* Give the netlink code an opportunity to put its own stuff in the
        message (configuration information, etc.) */
     buf_prepend_uint32(&st->buffer,LABEL_MSG6);
@@ -1225,7 +1225,7 @@ static bool_t send_msg7(struct site *st, cstring_t reason)
     if (current_valid(st) && st->buffer.free
        && transport_peers_valid(&st->peers)) {
        BUF_ALLOC(&st->buffer,"site:MSG7");
-       buffer_init(&st->buffer,st->transform->max_start_pad+(4*3));
+       buffer_init(&st->buffer,st->current.transform->max_start_pad+(4*3));
        buf_append_uint32(&st->buffer,LABEL_MSG7);
        buf_append_string(&st->buffer,reason);
        if (call_transform_forwards(st, st->current.transform,
index b3c70a8..de19817 100644 (file)
@@ -51,6 +51,7 @@
        ti->ops.forwards=transform_forward;             \
        ti->ops.reverse=transform_reverse;              \
        ti->ops.destroy=transform_destroy;              \
+       ti->ops.max_start_pad=st->ops.max_start_pad;    \
        ti->keyed=False;
 
 #endif /*TRANSFORM_COMMON_H*/
diff --git a/util.c b/util.c
index 1b46bc0..cfaefd2 100644 (file)
--- a/util.c
+++ b/util.c
@@ -247,6 +247,7 @@ void buffer_assert_used(struct buffer_if *buffer, cstring_t file,
 
 void buffer_init(struct buffer_if *buffer, int32_t max_start_pad)
 {
+    assert(max_start_pad<=buffer->len);
     buffer->start=buffer->base+max_start_pad;
     buffer->size=0;
 }