Chris Green <[EMAIL PROTECTED]> writes:

> I'm just now learning NASL to do things more complicated than an
> automated wget.  Is there a special ordering that the display()
> requires?

No. But you found a bug, congratulations! The bug is in the loop, not
in display(). It comes from an old behaviour that was disabled by
default with #ifdef STOP_AT_FIRST_ERROR
It is still here because it might be an interesting behaviour after
all... 

By the way, inspecting the rest of the code, I found a couple of other
similar errors, e.g. with if / else
if (test) expr1; else expr2; 
will execute neither expr1 or expr2 if the test returns an error
Note that this case does not happen often, that's why it was
undetected until now.

Here is a patch... 
I let Renaud decide if we commit it now (we probably need some testing
to check that it did not break some test that would rely on the bug)

--- nasl/exec.c	1 Mar 2003 12:16:53 -0000	1.42
+++ nasl/exec.c	31 Mar 2003 22:07:07 -0000
@@ -793,8 +793,11 @@
   switch(st->type)
     {
     case NODE_IF_ELSE:
-      if ((ret = nasl_exec(lexic, st->link[0])) == NULL)
+      ret = nasl_exec(lexic, st->link[0]);
+#ifdef STOP_AT_FIRST_ERROR
+      if (ret == NULL)
 	return NULL;
+#endif
       if (cvt_bool(lexic, ret))
 	ret2 = nasl_exec(lexic, st->link[1]);
       else
@@ -819,8 +822,11 @@
 	
     case NODE_FOR:
       /* [0] = start expr, [1] = cond, [2] = end_expr, [3] = block */
-      if ((ret2 = nasl_exec(lexic, st->link[0])) == NULL)
+      ret2 = nasl_exec(lexic, st->link[0]);
+#ifdef STOP_AT_FIRST_ERROR
+      if (ret2 == NULL)
 	return NULL;
+#endif
       deref_cell(ret2);
       for (;;)
 	{
@@ -833,14 +839,17 @@
 
 	  /* condition */
 	  if ((ret = nasl_exec(lexic, st->link[1])) == NULL)
-	    return NULL;
+	    return NULL;	/* We can return here, as NULL is false */
 	  flag = cvt_bool(lexic, ret);
 	  deref_cell(ret);
 	  if (! flag)
 	    break;
 	  /* block */
-	  if ((ret = nasl_exec(lexic, st->link[3])) == NULL)
+	  ret = nasl_exec(lexic, st->link[3]);
+#ifdef STOP_AT_FIRST_ERROR
+	  if (ret == NULL)
 	    return NULL;
+#endif
 	  deref_cell(ret);
 
 	  /* break */
@@ -851,8 +860,11 @@
 	    }
 
 	  /* end expression */
-	  if ((ret = nasl_exec(lexic, st->link[2])) == NULL)
+	  ret = nasl_exec(lexic, st->link[2]);
+#ifdef STOP_AT_FIRST_ERROR
+	  if (ret == NULL)
 	    return NULL;
+#endif
 	  deref_cell(ret); 
 	}
       return FAKE_CELL;
@@ -869,7 +881,7 @@
 	    }
 	  /* Condition */
 	  if ((ret = nasl_exec(lexic, st->link[0])) == NULL)
-	    return NULL;
+	    return NULL;	/* NULL is false */
 	  flag = cvt_bool(lexic, ret);
 	  deref_cell(ret);
 	  if (! flag)
@@ -937,7 +949,7 @@
 
 	v = get_variable_by_name(lexic, st->x.str_val);
 	if (v == NULL)
-	  return NULL;
+	  return NULL;		/* We cannot go on if we have no variable to iterate */
 	a = nasl_exec(lexic, st->link[0]); 
 	ai = nasl_array_iterator(a);
 	while ((val = nasl_iterate_array(&ai)) != NULL)

Reply via email to