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 46aac5b4a9c08b0a3dfe1eabf75e23521b527952..2ccf161989507e43fbf1e326ca69a5c04b0ed55b 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 2cb53f6038a8fc8775eabdc7e88b33e9298d42e9..2ada372edfadc88e1d354ddcb92e34926f5bdb8b 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 b3c70a8d30e3bcc49818547b495276330892521d..de198176cdd81ef15e0c01cbb5a446969771341a 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 1b46bc0df7422fe0bc6fdc2c3a91c0da51dba673..cfaefd227148c5f908f707b6f0b31ba48f21037c 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;
 }