INN commit: branches/2.5/innd (art.c innd.h keywords.c)

INN Commit rra at isc.org
Thu Oct 1 19:24:43 UTC 2009


    Date: Thursday, October 1, 2009 @ 12:24:43
  Author: eagle
Revision: 8644

Update keyword code to match current article handling

We no longer copy the article out of the channel and nul-terminate it,
but the keyword generation code was assuming that the article was 
nul-terminated.  Modify KEYgenerate to take an article length and use
xmalloc/memcpy to make a copy rather than strdup.  Thanks to Nix for
the report.

Modified:
  branches/2.5/innd/art.c
  branches/2.5/innd/innd.h
  branches/2.5/innd/keywords.c

------------+
 art.c      |    2 +-
 innd.h     |    2 +-
 keywords.c |   21 +++++++++++++--------
 3 files changed, 15 insertions(+), 10 deletions(-)

Modified: art.c
===================================================================
--- art.c	2009-10-01 19:24:16 UTC (rev 8643)
+++ art.c	2009-10-01 19:24:43 UTC (rev 8644)
@@ -1886,7 +1886,7 @@
 	key_old_value  = HDR(HDR__KEYWORDS);
 	key_old_length = HDR_LEN(HDR__KEYWORDS);
 	KEYgenerate(&hc[HDR__KEYWORDS], cp->In.data + data->Body,
-                    key_old_value, key_old_length);
+                    cp->Next - data->Body, key_old_value, key_old_length);
       }
     }
 

Modified: innd.h
===================================================================
--- innd.h	2009-10-01 19:24:16 UTC (rev 8643)
+++ innd.h	2009-10-01 19:24:43 UTC (rev 8644)
@@ -744,7 +744,7 @@
 extern void		CCclose(void);
 extern void		CCsetup(void);
 
-extern void             KEYgenerate(HDRCONTENT *, const char *body,
+extern void             KEYgenerate(HDRCONTENT *, const char *body, size_t,
                                     const char *orig, size_t length);
 
 extern void		LCclose(void);

Modified: keywords.c
===================================================================
--- keywords.c	2009-10-01 19:24:16 UTC (rev 8643)
+++ keywords.c	2009-10-01 19:24:43 UTC (rev 8644)
@@ -26,7 +26,8 @@
 #if !DO_KEYWORDS
 void
 KEYgenerate(HDRCONTENT *header UNUSED, const char *body UNUSED,
-            const char *orig UNUSED, size_t length UNUSED)
+            size_t bodylen UNUSED, const char *orig UNUSED,
+            size_t length UNUSED)
 {
 }
 
@@ -89,13 +90,14 @@
 
 void
 KEYgenerate(
-    HDRCONTENT	*hc,	/* header data */
-    const char	*body,	/* article body */
-    const char	*v,	/* old kw value */
-    size_t	l)	/* old kw length */
+    HDRCONTENT	*hc,		/* header data */
+    const char	*body,		/* article body */
+    size_t      bodylen,	/* article body length */
+    const char	*v,		/* old kw value */
+    size_t	l)		/* old kw length */
 {
 
-    int		word_count, word_length, bodylen, word_index, distinct_words;
+    int		word_count, word_length, word_index, distinct_words;
     int		last;
     char	*text, *orig_text, *text_end, *this_word, *chase, *punc;
     static struct word_entry	*word_vec;
@@ -145,11 +147,14 @@
      * now figure acceptable extents, and copy body to working string.
      * (Memory-intensive for hefty articles: limit to non-ABSURD articles.)
      */
-    bodylen = strlen(body);
     if ((bodylen < 100) || (bodylen > innconf->keyartlimit)) /* too small/big to bother */
 	return;
 
-    orig_text = text = xstrdup(body);	/* orig_text is for free() later on */
+    /* Nul-terminate the body.  orig_text will be freed later. */
+    orig_text = xmalloc(bodylen + 1);
+    memcpy(orig_text, body, bodylen);
+    orig_text[bodylen] = '\0';
+    text = orig_text;
 
     text_end = text + bodylen;
 




More information about the inn-committers mailing list