Subject: FIX: Re: INN 1.5 VS 1.5b2, perl filtering trouble

From: [email-masked] (Andy Burgess)
Date: 11 Dec 1996 13:39:46 -0800

In <[email-masked]> [email-masked] (Andy Burgess) writes:

>I have been attempting to upgrade from INN 1.5b2 to 1.5. Both versions
>use almost the same config.data, exactly the same perl (5.003) and 
>filter_innd.pl (config diff at the end of this post). I switch between
>versions by running make update in the appropriate directories).

This was caused by the perl memory leak fixes in 1.5.

The perl lib macro FREETMPS frees the return value from the perl
function filter_art. The value was returned from HandleArticle() in
perl.c, a classic using memory after freeing it bug.  The following
patch fixes this.

This was causing intermittant garbage returns from filter_art and thus
garbage reasons for rejection in the log file, eg:

innd: rejecting[perl] <[email-masked]> 437 xH
Dec  9 18:14:16.377 - news.scruz.net <[email-masked]
m> 437 xH

There is another bug which I haven't fixed yet whereby optional article
headers are not cleared from the perl hdr array. Thus when you get a
header with a Control line, the hdr array has the same control line
value for all subsequent articles in the perl program that do not have
Control header lines.  This can be worked around in the perl code by
including the following line in filter_art after you are finished with
the hdr array:

$hdr{"Control"} = "";

I don't know how to fix this in perl.c without leaking memory but its
just a perl manpage read away.

Thanks to everyone who ever worked on inn :-)

========================================================================

*** perl.c.orig	Wed Dec 11 12:49:04 1996
--- perl.c	Wed Dec 11 13:14:56 1996
***************
*** 39,45 ****
     ARTHEADER	*hp;
     HV		*hdr;
     int		rc;
!    char		*p;
  
     if (!PerlFilterActive || perl_filter_cv == NULL)
       return NULL;
--- 39,46 ----
     ARTHEADER	*hp;
     HV		*hdr;
     int		rc;
!    char		*p = NULL; /* may not get set below */
!    static char	buf[200];
  
     if (!PerlFilterActive || perl_filter_cv == NULL)
       return NULL;
***************
*** 46,51 ****
--- 47,55 ----
  
     /* Create the Perl Hash */
     hdr = perl_get_hv("hdr", TRUE);
+ 
+    /* fix the Control header not being reset bug */
+    /* hv_store(hdr, "Control", sizeof("Control"), ... */
     for (hp = ARTheaders; hp < ARTheadersENDOF; hp++)
       {
         if (hp->Found && hp->Value)
***************
*** 70,82 ****
       {
       p = POPp;
     }
  
     PUTBACK;
     FREETMPS;
     LEAVE;
  
!    if (p != NULL && *p != '\0')
!       return p;
     return NULL;
  }
  
--- 74,93 ----
       {
       p = POPp;
     }
+    if(p != NULL && *p != '\0') 
+      {
+      strncpy(buf, p, sizeof(buf)-1);
+      buf[sizeof(buf)-1] = '\0';
+      } 
+    else
+      *buf = '\0';
  
     PUTBACK;
     FREETMPS;
     LEAVE;
  
!    if (*buf != '\0')
!       return buf;
     return NULL;
  }