From 2b863855d5e33a12dee06111e1e2594b19da016e Mon Sep 17 00:00:00 2001 From: Bart Trojanowski Date: Thu, 17 Aug 2006 14:14:15 -0400 Subject: [PATCH] added dump_core() and assert_id_valid() to catch the location that makes the connections list break --- include/dump_core.h | 26 ++++++++++++++++++++++++++ programs/pluto/connections.c | 7 ++++++- programs/pluto/id.c | 1 + programs/pluto/id.h | 10 ++++++++++ programs/pluto/ipsec_doi.c | 1 + 5 files changed, 44 insertions(+), 1 deletions(-) diff --git a/include/dump_core.h b/include/dump_core.h new file mode 100644 index 0000000..5061ad1 --- /dev/null +++ b/include/dump_core.h @@ -0,0 +1,26 @@ +#ifndef __dump_core_h__ +#define __dump_core_h__ + +#include +#include +#include +#include + +#include "openswan/passert.h" // passert + +#define dump_core_if(bad_condition) do { \ + if ((bad_condition)) { \ + int __pid = fork(); \ + passert (__pid >= 0); \ + if (__pid == 0) { \ + /* child, dump core */ \ + abort(); \ + } else if (__pid > 0) { \ + /* parent, wait */ \ + waitpid (__pid, NULL, 0); \ + } \ + } \ +} while (0) \ + + +#endif // __dump_core_h__ diff --git a/programs/pluto/connections.c b/programs/pluto/connections.c index c2a9d30..bccc4cc 100644 --- a/programs/pluto/connections.c +++ b/programs/pluto/connections.c @@ -1532,6 +1532,7 @@ instantiate(struct connection *c, const passert(c->kind == CK_TEMPLATE); passert(c->spd.next == NULL); + if (his_id) assert_valid_id(his_id); c->instance_serial++; d = clone_thing(*c, "temporary connection"); @@ -1592,7 +1593,11 @@ rw_instantiate(struct connection *c , const ip_subnet *his_net , const struct id *his_id) { - struct connection *d = instantiate(c, him, his_id); + struct connection *d; + + if (his_id) assert_valid_id(his_id); + + d = instantiate(c, him, his_id); #ifdef VIRTUAL_IP if (d && his_net && is_virtual_connection(c)) { diff --git a/programs/pluto/id.c b/programs/pluto/id.c index 2f822d7..3a24d79 100644 --- a/programs/pluto/id.c +++ b/programs/pluto/id.c @@ -418,6 +418,7 @@ unshare_id_content(struct id *id) case ID_DER_ASN1_DN: case ID_KEY_ID: id->name.ptr = clone_bytes(id->name.ptr, id->name.len, "keep id name"); + assert_valid_id(id); break; case ID_MYID: case ID_NONE: diff --git a/programs/pluto/id.h b/programs/pluto/id.h index e67e8ce..c84dc69 100644 --- a/programs/pluto/id.h +++ b/programs/pluto/id.h @@ -14,6 +14,8 @@ * RCSID $Id: id.h,v 1.23 2005/02/14 05:56:02 ken Exp $ */ +#include "dump_core.h" + struct id { int kind; /* ID_* value */ ip_address ip_addr; /* ID_IPV4_ADDR, ID_IPV6_ADDR */ @@ -59,3 +61,11 @@ #define id_is_ipaddr(id) ((id)->kind == struct isakmp_ipsec_id; /* forward declaration of tag (defined in packet.h) */ extern void build_id_payload(struct isakmp_ipsec_id *hd, chunk_t *tl, struct end *end); + +#define assert_valid_id(idptr) do { \ + struct id *__id = idptr; \ + if (__id->name.ptr || __id->name.len) { \ + dump_core_if(__id->name.ptr == NULL); \ + dump_core_if(__id->name.len == 0); \ + } \ +} while (0) diff --git a/programs/pluto/ipsec_doi.c b/programs/pluto/ipsec_doi.c index 1f56c64..12629c5 100644 --- a/programs/pluto/ipsec_doi.c +++ b/programs/pluto/ipsec_doi.c @@ -1959,6 +1959,7 @@ #endif } else if (c->spd.that.has_id_wildcards) { + assert_valid_id(&peer); free_id_content(&c->spd.that.id); c->spd.that.id = peer; c->spd.that.has_id_wildcards = FALSE; -- 1.4.2.rc2.g432f-dirty