- Fixed a memory error.

This commit is contained in:
ccremers 2004-08-19 14:49:03 +00:00
parent 35c55c9483
commit f25f0abd4e
3 changed files with 142 additions and 95 deletions

View File

@ -111,7 +111,7 @@ arachneInit (const System mysys)
add_event (READ, NULL); add_event (READ, NULL);
add_event (READ, NULL); add_event (READ, NULL);
add_event (SEND, NULL); add_event (SEND, NULL);
I_RRS = add_role ("I_D: Encrypt"); I_RRS = add_role ("I_E: Encrypt");
return; return;
} }
@ -172,12 +172,12 @@ semiRunCreate (const Protocol p, const Role r)
{ {
int run; int run;
run = sys->maxruns;
if (p == INTRUDER) if (p == INTRUDER)
num_intruder_runs++; num_intruder_runs++;
else else
num_regular_runs++; num_regular_runs++;
roleInstance (sys, p, r, NULL, NULL); roleInstance (sys, p, r, NULL, NULL);
run = sys->maxruns-1;
sys->runs[run].length = 0; sys->runs[run].length = 0;
return run; return run;
} }
@ -185,6 +185,8 @@ semiRunCreate (const Protocol p, const Role r)
//! Wrapper for roleDestroy //! Wrapper for roleDestroy
void void
semiRunDestroy () semiRunDestroy ()
{
if (sys->maxruns > 0)
{ {
Protocol p; Protocol p;
@ -195,6 +197,7 @@ semiRunDestroy ()
else else
num_regular_runs--; num_regular_runs--;
} }
}
//! After a role instance, or an extension of a run, we might need to add some goals //! After a role instance, or an extension of a run, we might need to add some goals
/** /**
@ -765,6 +768,7 @@ bind_goal_new_m0 (const Binding b)
goal_unbind (b); goal_unbind (b);
indentDepth--; indentDepth--;
semiRunDestroy (); semiRunDestroy ();
termlistSubstReset (subst); termlistSubstReset (subst);
termlistDelete (subst); termlistDelete (subst);
} }
@ -792,9 +796,11 @@ bind_goal_new_encrypt (const Binding b)
{ {
Term term; Term term;
int flag; int flag;
int can_be_encrypted;
flag = 1; flag = 1;
term = b->term; term = deVar(b->term);
can_be_encrypted = 0;
if (!realTermLeaf (term)) if (!realTermLeaf (term))
{ {
@ -804,7 +810,7 @@ bind_goal_new_encrypt (const Binding b)
Roledef rd; Roledef rd;
Term t1, t2; Term t1, t2;
if (realTermTuple (term)) if (!realTermEncrypt (term))
{ {
// tuple construction // tuple construction
error ("Goal that is a tuple should not occur!"); error ("Goal that is a tuple should not occur!");
@ -814,11 +820,14 @@ bind_goal_new_encrypt (const Binding b)
t1 = term->left.op; t1 = term->left.op;
t2 = term->right.key; t2 = term->right.key;
if (t2 != TERM_Hidden)
{
can_be_encrypted = 1;
run = semiRunCreate (INTRUDER, I_RRS); run = semiRunCreate (INTRUDER, I_RRS);
rd = sys->runs[run].start; rd = sys->runs[run].start;
rd->message = termDuplicate (t1); //rd->message = termDuplicateUV (t1);
rd->next->message = termDuplicate (t2); //rd->next->message = termDuplicateUV (t2);
rd->next->next->message = termDuplicate (term); rd->next->next->message = termDuplicateUV (term);
index = 2; index = 2;
proof_suppose_run (run, 0, index + 1); proof_suppose_run (run, 0, index + 1);
if (sys->output == PROOF) if (sys->output == PROOF)
@ -833,6 +842,7 @@ bind_goal_new_encrypt (const Binding b)
eprintf ("\n"); eprintf ("\n");
} }
newgoals = add_read_goals (run, 0, index + 1); newgoals = add_read_goals (run, 0, index + 1);
indentDepth++; indentDepth++;
if (goal_bind (b, run, index)) if (goal_bind (b, run, index))
{ {
@ -848,7 +858,9 @@ bind_goal_new_encrypt (const Binding b)
remove_read_goals (newgoals); remove_read_goals (newgoals);
semiRunDestroy (); semiRunDestroy ();
} }
else }
if (!can_be_encrypted)
{ {
if (sys->output == PROOF) if (sys->output == PROOF)
{ {
@ -1375,26 +1387,25 @@ arachne ()
proof_suppose_run (run, 0, cl->ev + 1); proof_suppose_run (run, 0, cl->ev + 1);
add_read_goals (run, 0, cl->ev + 1); add_read_goals (run, 0, cl->ev + 1);
/** /**
* Add specific goal info * Add specific goal info
*/ */
add_claim_specifics (cl, add_claim_specifics (cl,
roledef_shift (sys->runs[run].start, cl->ev)); roledef_shift (sys->runs[run].start, cl->ev));
#ifdef DEBUG #ifdef DEBUG
if (DEBUGL (5)) if (DEBUGL (5))
{ {
printSemiState (); printSemiState ();
} }
#endif #endif
// Iterate
/*
* iterate
*/
iterate (); iterate ();
//! Destroy //! Destroy
while (sys->bindings != NULL)
{
remove_read_goals (1);
}
while (sys->maxruns > 0) while (sys->maxruns > 0)
{ {
semiRunDestroy (); semiRunDestroy ();

View File

@ -433,7 +433,7 @@ termDuplicate (const Term term)
return term; return term;
newterm = (Term) memAlloc (sizeof (struct term)); newterm = (Term) memAlloc (sizeof (struct term));
newterm->type = term->type; memcpy (newterm, term, sizeof (struct term));
if (realTermEncrypt (term)) if (realTermEncrypt (term))
{ {
newterm->left.op = termDuplicate (term->left.op); newterm->left.op = termDuplicate (term->left.op);
@ -464,13 +464,9 @@ termDuplicateDeep (const Term term)
return NULL; return NULL;
newterm = (Term) memAlloc (sizeof (struct term)); newterm = (Term) memAlloc (sizeof (struct term));
if (realTermLeaf (term))
{
memcpy (newterm, term, sizeof (struct term)); memcpy (newterm, term, sizeof (struct term));
} if (!realTermLeaf (term))
else
{ {
newterm->type = term->type;
if (realTermEncrypt (term)) if (realTermEncrypt (term))
{ {
newterm->left.op = termDuplicateDeep (term->left.op); newterm->left.op = termDuplicateDeep (term->left.op);
@ -496,14 +492,14 @@ termDuplicateUV (Term term)
{ {
Term newterm; Term newterm;
term = deVar (term);
if (term == NULL) if (term == NULL)
return NULL; return NULL;
term = deVar (term);
if (realTermLeaf (term)) if (realTermLeaf (term))
return term; return term;
newterm = (Term) memAlloc (sizeof (struct term)); newterm = (Term) memAlloc (sizeof (struct term));
newterm->type = term->type; memcpy (newterm, term, sizeof (struct term));
if (realTermEncrypt (term)) if (realTermEncrypt (term))
{ {
newterm->left.op = termDuplicateUV (term->left.op); newterm->left.op = termDuplicateUV (term->left.op);
@ -676,7 +672,7 @@ tupleCount (Term tt)
} }
else else
{ {
deVar (tt); tt = deVar (tt);
if (!realTermTuple (tt)) if (!realTermTuple (tt))
{ {
return 1; return 1;
@ -702,7 +698,7 @@ tupleProject (Term tt, int n)
{ {
return NULL; return NULL;
} }
deVar (tt); tt = deVar (tt);
if (!realTermTuple (tt)) if (!realTermTuple (tt))
{ {
if (n > 0) if (n > 0)
@ -956,32 +952,62 @@ term_iterate (const Term term, int (*leaf) (), int (*nodel) (),
if (noder != NULL) if (noder != NULL)
flag = flag && noder (term); flag = flag && noder (term);
return flag;
} }
} }
return 1; return 1;
} }
//! Generic term iteration with deVar //! Generic term iteration
int int
term_iterate_deVar (const Term term, int (*leaf) (), int (*nodel) (), term_iterate_deVar (Term term, int (*leaf) (), int (*nodel) (),
int (*nodem) (), int (*noder) ()) int (*nodem) (), int (*noder) ())
{ {
int deVar_leaf (const Term term) term = deVar (term);
if (term != NULL)
{ {
if (substVar (term)) if (realTermLeaf (term))
{ {
return term_iterate_deVar (term->subst, deVar_leaf, nodel, nodem, // Leaf
noder); if (leaf != NULL)
}
else
{ {
if (leaf == NULL)
return 1;
else
return leaf (term); return leaf (term);
} }
} }
return term_iterate (term, deVar_leaf, nodel, nodem, noder); else
{
int flag;
flag = 1;
if (nodel != NULL)
flag = flag && nodel (term);
if (realTermTuple (term))
flag = flag
&& (term_iterate_deVar (term->left.op1, leaf, nodel, nodem, noder));
else
flag = flag
&& (term_iterate_deVar (term->left.op, leaf, nodel, nodem, noder));
if (nodem != NULL)
flag = flag && nodem (term);
if (realTermTuple (term))
flag = flag
&& (term_iterate_deVar (term->left.op1, leaf, nodel, nodem, noder));
else
flag = flag
&& (term_iterate_deVar (term->left.op, leaf, nodel, nodem, noder));
if (noder != NULL)
flag = flag && noder (term);
return flag;
}
}
return 1;
} }
//! Iterate over the leaves in a term //! Iterate over the leaves in a term
@ -1082,19 +1108,29 @@ term_constrain_level (const Term term)
int structure; int structure;
int flag; int flag;
int leaf (const Term t) void
tcl_iterate (Term t)
{ {
t = deVar (t);
structure++; structure++;
if (realTermLeaf (t))
{
if (realTermVariable (t)) if (realTermVariable (t))
vars++; vars++;
return 1;
} }
int nodel (const Term t) else
{ {
structure++;
if (realTermTuple (t)) if (realTermTuple (t))
structure++; {
return 1; tcl_iterate (t->left.op1);
tcl_iterate (t->right.op2);
}
else
{
tcl_iterate (t->left.op);
tcl_iterate (t->right.key);
}
}
} }
if (term == NULL) if (term == NULL)
@ -1102,6 +1138,6 @@ term_constrain_level (const Term term)
vars = 0; vars = 0;
structure = 0; structure = 0;
flag = term_iterate_deVar (term, leaf, nodel, NULL, NULL); tcl_iterate (term);
return ((float) vars / (float) structure); return ((float) vars / (float) structure);
} }

View File

@ -170,7 +170,7 @@ float termDistance (Term t1, Term t2);
int termOrder (Term t1, Term t2); int termOrder (Term t1, Term t2);
int term_iterate (const Term term, int (*leaf) (), int (*nodel) (), int term_iterate (const Term term, int (*leaf) (), int (*nodel) (),
int (*nodem) (), int (*noder) ()); int (*nodem) (), int (*noder) ());
int term_iterate_deVar (const Term term, int (*leaf) (), int (*nodel) (), int term_iterate_deVar (Term term, int (*leaf) (), int (*nodel) (),
int (*nodem) (), int (*noder) ()); int (*nodem) (), int (*noder) ());
int term_iterate_leaves (const Term t, int (*func) ()); int term_iterate_leaves (const Term t, int (*func) ());
int term_iterate_open_leaves (const Term term, int (*func) ()); int term_iterate_open_leaves (const Term term, int (*func) ());