[PATCH 22/25] site, transform: per-transform-instance max_start_pad
Ian Jackson
ijackson at chiark.greenend.org.uk
Sat Jul 20 00:39:06 BST 2013
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 at chiark.greenend.org.uk>
---
secnet.h | 1 +
site.c | 6 +++---
transform-common.h | 1 +
util.c | 1 +
4 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/secnet.h b/secnet.h
index 41578b4..3db0f6c 100644
--- a/secnet.h
+++ b/secnet.h
@@ -411,6 +411,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 817d5e4..35c2814 100644
--- a/site.c
+++ b/site.c
@@ -731,7 +731,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);
@@ -777,7 +777,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);
@@ -1188,7 +1188,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);
st->current.transform->forwards(st->current.transform->st,
diff --git a/transform-common.h b/transform-common.h
index b3c70a8..de19817 100644
--- a/transform-common.h
+++ b/transform-common.h
@@ -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 d47b944..8228280 100644
--- a/util.c
+++ b/util.c
@@ -244,6 +244,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;
}
--
1.7.2.5
More information about the sgo-software-discuss
mailing list