INN commit: branches/2.6/innd (art.c newsfeeds.c site.c)

INN Commit rra at isc.org
Fri Nov 25 22:39:35 UTC 2016


    Date: Friday, November 25, 2016 @ 14:39:35
  Author: iulius
Revision: 10122

Use a buffer properly for Site.FNLnames

We were using a buffer to store the space-separated list of feed
names to which a funnel feed was being sent, but only by directly
manipulating the underlying struct with (incorrect) uses of strlcpy
and strlcat.  Use the buffer API to manipulate this structure
correctly, and fix up the other places where "used" was incorrectly
used as the length of data in the buffer instead of "left".

Modified:
  branches/2.6/innd/art.c
  branches/2.6/innd/newsfeeds.c
  branches/2.6/innd/site.c

-------------+
 art.c       |   13 ++++---------
 newsfeeds.c |    9 +--------
 site.c      |   14 +++++++-------
 3 files changed, 12 insertions(+), 24 deletions(-)

Modified: art.c
===================================================================
--- art.c	2016-11-23 21:32:53 UTC (rev 10121)
+++ art.c	2016-11-25 22:39:35 UTC (rev 10122)
@@ -1670,7 +1670,6 @@
   SITE		*sp, *funnel;
   int		i, j, Groupcount, Followcount, Crosscount;
   char	        *p, *q, *begin, savec;
-  struct buffer	*bp;
   bool		sendit;
 
   /* Work out which sites should really get it. */
@@ -1813,13 +1812,9 @@
       funnel = &Sites[sp->Funnel];
       funnel->Sendit = true;
       if (funnel->FNLwantsnames) {
-	bp = &funnel->FNLnames;
-	p = &bp->data[bp->used];
-	if (bp->used) {
-	  *p++ = ' ';
-	  bp->used++;
-	}
-	bp->used += strlcpy(p, sp->Name, bp->size - bp->used);
+        if (funnel->FNLnames.left != 0)
+          buffer_append(&funnel->FNLnames, " ", 1);
+        buffer_append(&funnel->FNLnames, sp->Name, strlen(sp->Name));
       }
     }
   }
@@ -2181,7 +2176,7 @@
     sp->Poison = false;
     sp->Sendit = false;
     sp->Seenit = false;
-    sp->FNLnames.used = 0;
+    buffer_set(&sp->FNLnames, NULL, 0);
     sp->ng = NULL;
   }
 

Modified: newsfeeds.c
===================================================================
--- newsfeeds.c	2016-11-23 21:32:53 UTC (rev 10121)
+++ newsfeeds.c	2016-11-25 22:39:35 UTC (rev 10122)
@@ -842,14 +842,7 @@
 	    result = false;
 	    continue;
 	}
-	if (funnel->FNLnames.data == NULL) {
-	    funnel->FNLnames.size = length;
-	    funnel->FNLnames.data = xmalloc(length);
-	}
-	else if (funnel->FNLnames.size != length) {
-	    funnel->FNLnames.size = length;
-            funnel->FNLnames.data = xrealloc(funnel->FNLnames.data, length);
-	}
+	buffer_resize(&funnel->FNLnames, length);
 	sp->Funnel = funnel - Sites;
     }
 

Modified: site.c
===================================================================
--- site.c	2016-11-23 21:32:53 UTC (rev 10121)
+++ site.c	2016-11-25 22:39:35 UTC (rev 10122)
@@ -447,11 +447,11 @@
 	    buffer_append(bp, HDR(HDR__MESSAGE_ID), HDR_LEN(HDR__MESSAGE_ID));
 	    break;
 	case FEED_FNLNAMES:
-	    if (sp->FNLnames.data) {
+	    if (sp->FNLnames.left != 0) {
 		/* Funnel; write names of our sites that got it. */
 		if (Dirty)
 		    buffer_append(bp, ITEMSEP, strlen(ITEMSEP));
-		buffer_append(bp, sp->FNLnames.data, sp->FNLnames.used);
+		buffer_append(bp, sp->FNLnames.data, sp->FNLnames.left);
 	    }
 	    else {
 		/* Not funnel; write names of all sites that got it. */
@@ -516,7 +516,7 @@
     case FTprogram:
 	/* Set up the argument vector. */
 	if (sp->FNLwantsnames) {
-	    i = strlen(sp->Param) + sp->FNLnames.used;
+	    i = strlen(sp->Param) + sp->FNLnames.left;
 	    if (i + (sizeof(TOKEN) * 2) + 3 >= sizeof buff) {
 		syslog(L_ERROR, "%s toolong need %lu for %s",
 		    sp->Name, (unsigned long) (i + (sizeof(TOKEN) * 2) + 3),
@@ -523,12 +523,10 @@
 		    sp->Name);
 		break;
 	    }
-	    temp = xmalloc(i + 1);
 	    p = strchr(sp->Param, '*');
 	    *p = '\0';
-	    strlcpy(temp, sp->Param, i + 1);
-	    strlcat(temp, sp->FNLnames.data, i + 1);
-	    strlcat(temp, &p[1], i + 1);
+	    xasprintf(&temp, "%s%.*s%s", sp->Param, (int) sp->FNLnames.left,
+		      sp->FNLnames.data, &p[1]);
 	    *p = '*';
 	    snprintf(buff, sizeof(buff), temp, Data->TokenText);
 	    free(temp);
@@ -1067,6 +1065,8 @@
 	free(sp->FNLnames.data);
 	sp->FNLnames.data = NULL;
 	sp->FNLnames.size = 0;
+	sp->FNLnames.left = 0;
+	sp->FNLnames.used = 0;
     }
     if (sp->HashFeedList) {
         for (hf = sp->HashFeedList; hf; hf = hn) {



More information about the inn-committers mailing list